Documentation ¶
Index ¶
- func APIMiddleware(cfg conf.IConf, logger *logrus.Entry, jwtSecret []byte) gin.HandlerFunc
- func AuthFunction(account, pwd string) error
- func AuthRequired(c *gin.Context)
- func CorsConfig() cors.Config
- func GenerateToken(jwtSecret []byte, account, role string) (string, error)
- func GetServiceInfo(c *gin.Context)
- func Login(c *gin.Context)
- func RunServer(cfg conf.IConf, logger *logrus.Entry) error
- func SetupServer(cfg conf.IConf, logger *logrus.Entry) (*gin.Engine, error)
- func ValidateAPIKey(c *gin.Context)
- type AuthFailedResp
- type Claims
- type LoginFailed
- type LoginReceiveBody
- type LoginSucceed
- type ServiceInfoFailedResp
- type ServiceInfoSuccessResp
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func APIMiddleware ¶
APIMiddleware will add middleware to the context
func AuthFunction ¶
func CorsConfig ¶
This function is used to setup cors, and setup allowed methods and headers
func GenerateToken ¶
A function to generate token
func GetServiceInfo ¶
API to get service list Swagger comments: @Summary get service info @Description get service info @Param Authorization header string true "Insert your access token" default(Bearer <Add access token here>) @Accept json @Produce json @Tags Service Information @version 1.0 @Success 200 {object} ServiceInfoSuccessResp "Get service info by GET method with token" @Failure 400 {object} ServiceInfoFailedResp @Failure 401 {object} AuthFailedResp @Failure 500 {object} ServiceInfoFailedResp @Router /api/v1/getServiceInfo [get]
func Login ¶
@Summary Login and return token after authenticate. @Description login and get token @Param X-API-Key header string true "Insert your api key" default(<Add api key here>) @Accept json @Produce json @Param Body body LoginReceiveBody true "Account and Password" @Tags AAA @version 1.0 @produce text/plain @Success 200 {object} LoginSucceed @Failure 400 {object} LoginFailed @Failure 401 {object} AuthFailedResp @Failure 500 {object} LoginFailed @Router /api/v1/login [post]
Types ¶
type AuthFailedResp ¶
type AuthFailedResp struct {
ErrorString string `json:"error" example:"error"`
}
Auth failed resp, will be used when 401 in all api path
type Claims ¶
type Claims struct { Account string `json:"account"` Role string `json:"role"` jwt.StandardClaims }
Claim format in JWT
type LoginFailed ¶
type LoginFailed struct {
Message string `json:"message" example:"msg" format:"string"`
}
type LoginReceiveBody ¶
type LoginSucceed ¶
type LoginSucceed struct {
Token string `` /* 336-byte string literal not displayed */
}
type ServiceInfoFailedResp ¶
type ServiceInfoFailedResp struct {
Message string `json:"message" example:"msg"`
}
type ServiceInfoSuccessResp ¶
type ServiceInfoSuccessResp struct {
ServiceName string `json:"serviceName" example:"service" format:"string"`
}
Service list response struct