How to implement authentication and authorization in Golang
· One min read
We planned to use following libraries:
-
Gin: http web framwork go get -u github.com/gin-gonic/gin
-
Gorm: ORM for relational database go get -u gorm.io/gorm
-
go-jwt github.com/golang-jwt/jwt
-
bycrypt:
-
godotenv:
-
Postgres database go get -u gorm.io/driver/postgres
Directory structure is as following
models/user.go
package models
import "gorm.io/gorm"
type User struct {
gorm.Model
Name string `json:"name"`
Email string `json:"email"`
Password string `json:"password"`
Role string `json:"role"`
}