Welcome to basic-auth-gin v1
The fastest way to deploy a restful api's with Gin Framework with a structured project that defaults to MongoDB database and JWT authentication middleware
- jwt-go: JSON Web Tokens (JWT) as middleware
- Go Modules
- Built-in Custom Validators
- Built-in CORS Middleware
- Built-in RequestID Middleware
- google oauth api
- sendGrid email api
- SSL Support
- Enviroment support
- Unit test
- swagger docs
- And few other important utilties to kickstart any project
- create oauth-client at https://console.cloud.google.com/apis/credentials
- set
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
in.env
to your oauth-client id and secret - set
REDIRECT_URI
for the google oauth callback
- if you have your own mail system, you can change the
sendEmail
function atcontrollers/user.go:146
and connect to your smtp server - if you dont have, try my free alternative:
cloudflare
+sendgrid
- after you get the sengrid email api key, set
SENDGRID_API_KEY
in.env
to that
FRONTEND_URI
: frontend url, this would be use when the google auth callback to bring acess_token to the clientEMAIL
: from emailREDIRECT_URI
: the redirect uri for google oauth, the endpoint will get the grant code from google oauth
$ git clone https://github.com/peterxcli/basic-auth-gin.git
Rename .env_rename_me
to .env
and place your credentials
$ mv .env_rename_me .env
Generate SSL certificates (Optional)
if you need ssl, change
SSL=FALSE
toSSL=TRUE
in the.env
file, then
$ make https
Make sure to change the values in .env for your database
$ make install
$ make run
- every time you run
$ make run
it would regenerate the swagger docs base on your comments
link to http://localhost:9000/swagger/index.html to view the openAPI docs
$ go build -v
$ ./<your_package_name>
$ make test
thanks Massad -> gin-boilerplate for enabling me to build the gin/mongoDB user auth template