Skip to content

A sample golang api to test, learn and have reference for implementing stuff

License

Notifications You must be signed in to change notification settings

vinpel/golang-sample-api-jwt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Issues MIT License LinkedIn


Logo

golang-sample-api-jwt

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
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

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

(back to top)

Built With

  • Go
  • Gin
  • Swaggo generate from anotations Swagger UI pages

(back to top)

Getting Started

.

Prerequisites

  • go
  • a mySQL database, use the one provided in docker or edit the main.go file
    docker-compose up

Installation

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.

  1. Clone the repo
    git clone https://github.com/vinpel/golang-sample-api-jwt.git
  2. Install dependencies and build the app
    go build .
  3. Start the app
    go run .

(back to top)

Usage

  swag init && go run .
  • Set the application in production mode (disable swagger endpoint)
    1. edit the main.go file
    2. add the following line before the routeur initilisation
gin.SetMode(gin.ReleaseMode)
  1. restart / build / install the app
   go build .

(back to top)

Roadmap

  • 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).

(back to top)

Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Vincent Pélisset - @g4spine

Project Link: https://github.com/vinpel/golang-sample-api-jwt

(back to top)

Acknowledgments

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!

(back to top)

About

A sample golang api to test, learn and have reference for implementing stuff

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages