Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 2.25 KB

README.md

File metadata and controls

43 lines (31 loc) · 2.25 KB

Beego + JWT + MySQL

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.

Installation & Running

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 two private.txt and public.txt files. Then put your Private RSA key text in public.txt and put your Public RSA key text in private.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

Then you can run the project by this command:

If you want Beego to generate API documentation automatically for you using Swagger definition you can use this command instead:

Use Postman or any other tool that you're comfortable with to test your API

Developer

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!