A sample Golang project that shows you how to create your APIs with Beego, also JWT (Json Web Token) is implemented. In this project I used MySQL database to store Users data.
You should first install Golang and register GOPATH
in your System Environment Valriables, read more in https://golang.org/doc/install.
Then install Beego and Bee Tool, read more in https://beego.me/quickstart
You need to install some pakcages that are used in this project, install them with: (I imagine that you've installed Beego & Bee Tool)
go get -u github.com/astaxie/beego/orm
(Beego ORM Helper)go get -u github.com/go-sql-driver/mysql
(MySQL Driver for Golang)go get -u golang.org/x/crypto/bcrypt
(Bcrypt helper to hash passwords)go get -u github.com/gbrlsnchs/jwt
(JWT Helper)go get -u github.com/SermoDigital/jose
(also JWT Helper but I just used rsa keys loader from that)
After preparing your environment, clone this repository in %GOPATH%\src\beego_jwt_mysql
.
- For signing Json-Web-Tokens I used RSA public/private key pair, you must create
keys
folder in the root of project and then create twoprivate.txt
andpublic.txt
files. Then put your Private RSA key text inpublic.txt
and put your Public RSA key text inprivate.txt
.- You can create RSA key pair by this commands: (You must have installed openssl on your system)
- Private Key:
openssl genrsa -out private.txt 2048
- Public Key:
openssl rsa -in private.txt -pubout > public.txt
- Private Key:
- You can create RSA key pair by this commands: (You must have installed openssl on your system)
Then you can run the project by this command:
bee run
Your app will run on :8080 port, You can visit site on http://localhost:8080
If you want Beego to generate API documentation automatically for you using Swagger definition you can use this command instead:
bee run -downdoc=true -gendoc=true
Then you can visit http://localhost:8080/swagger to view documentation.
Use Postman or any other tool that you're comfortable with to test your API
- Mehran Abghari
- Email: mehran.ab80@gmail.com
- Github: https://github.com/mehranabi
LICENSE: MIT
You can use this project for any purpose.
But if you like it, Let me know :) - Star It or Just send me a message!