Modified from repository eddycjy/go-gin-example (Docs)
go get github.com/yapkah/go-api
copy conf/app.sample.ini
to another file name conf/app.ini
and change the setting inside
generate public and private key for access token using command below:
cd ./storage/
- login vers.
openssl genrsa -out private.pem 4096
openssl rsa -in private.pem -out public.pem -pubout -outform PEM
- password vers.
openssl genrsa -out encrypt_private.pem 2048
openssl rsa -in encrypt_private.pem -out encrypt_public.pem -pubout -outform PEM
- bc admin vers.
openssl genrsa -out bc_admin_private.pem 4096
openssl rsa -in bc_admin_private.pem -out bc_admin_public.pem -pubout -outform PEM
import the sample table from docs/sql/template.sql
to your DB
run go install
at the root of the repo
middleware/jwt.go
(access token validation)pkg/util/jwt.go
(token generation function)pkg/setting/setting.go
(changevar Cfg
to be access by other package)conf/app.ini
added new config in section[custom]
pkg/app/form
changeBindAndValid()
functionpkg/app/response
(for return response)
comment line
auth.Use(jwt.JWT())
(for token authentication)memberGroup.Use(jwt.CheckScope("MEM"))
(for checking token scope)adminGroup.Use(jwt.CheckScope("ADM"))
(for checking token scope)
// authentication api group
auth := apiv1.Group("/")
auth.Use(jwt.JWT())
{
// member api
memberGroup := auth.Group("/member")
memberGroup.Use(jwt.CheckScope("MEM")) // check token scope
{
memberGroup.GET("/", member.GetMember) // get member
memberGroup.POST("/", member.AddMember) // add member
}
// admin api
adminGroup := auth.Group("/admin")
adminGroup.Use(jwt.CheckScope("ADM")) // check token scope
{
adminGroup.GET("/", admin.GetAdmin)
adminGroup.POST("/", admin.AddAdmin)
}
}
value to update under [custom] section
- AppName
- AdminServerDomain
- MemberServerDomain
- ApiServerDomain
- CryptoSalt1
- CryptoSalt2
- CryptoSalt3
- EncryptSalt
- PKSalt