A sample golang api to test, learn and have reference for implementing stuff
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
I wanted to build a test golang application able to :
- Connect to a mySQL database via gorm to store user data
- Use the Gin Web Framework to serve API
- Secure API via 2 JWT different token usage :
- a short lived "access token" (1 hour ) to use the API
- a long refresh JWT token (15 days ), only able to get new up-to-date access and refresh token
- Document the API via the Swagger UI
.
- go
- a mySQL database, use the one provided in docker or edit the main.go file
docker-compose up
Below is an example of how you can instruct your audience on installing and setting up your app. This template doesn't rely on any external dependencies or services.
- Clone the repo
git clone https://github.com/vinpel/golang-sample-api-jwt.git
- Install dependencies and build the app
go build .
- Start the app
go run .
-
Consult the API documentation
-
View the database content (db / root / root)
-
Launch a debug session : F5 in VScode
-
Stop a debug session : SHIFT + F5 in VScode
-
Recreate the swagger documentation and start the application
swag init && go run .
- Set the application in production mode (disable swagger endpoint)
- edit the main.go file
- add the following line before the routeur initilisation
gin.SetMode(gin.ReleaseMode)
- restart / build / install the app
go build .
- Add Gin Framework
- Add API endpoint to create a new user
- Add Swaggo annotations to generate swagger json/yaml file
- Add API endpoint to grab JWT tokens using user information email/passwod
- Add API endpoint to grab JWT tokens from a refresh token
- Add API secure endpoint to test the secure API (ping)
- Change password algorithm to Argon 2
- Add secure API to change the password (stay connected for other / disconnect)
- Manage configuration https://github.com/spf13/viper
- Add tests with ovh-venom
See the open issues for a full list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE.txt
for more information.
Vincent Pélisset - @g4spine
Project Link: https://github.com/vinpel/golang-sample-api-jwt
Use this space to list resources you find helpful and would like to give credit to. I've included a few of my favorites to kick things off!