api

package
v0.0.0-...-ce0cb31 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIMiddleware

func APIMiddleware(cfg conf.IConf, logger *logrus.Entry, jwtSecret []byte) gin.HandlerFunc

APIMiddleware will add middleware to the context

func AuthFunction

func AuthFunction(account, pwd string) error

func AuthRequired

func AuthRequired(c *gin.Context)

A function to check whether JWT met

func CorsConfig

func CorsConfig() cors.Config

This function is used to setup cors, and setup allowed methods and headers

func GenerateToken

func GenerateToken(jwtSecret []byte, account, role string) (string, error)

A function to generate token

func GetServiceInfo

func GetServiceInfo(c *gin.Context)

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

func Login(c *gin.Context)

@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]

func RunServer

func RunServer(cfg conf.IConf, logger *logrus.Entry) error

RunServer is used to run API server

func SetupServer

func SetupServer(cfg conf.IConf, logger *logrus.Entry) (*gin.Engine, error)

func ValidateAPIKey

func ValidateAPIKey(c *gin.Context)

A function to check whther APIKey met

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 LoginReceiveBody struct {
	Account  string `json:"Account" example:"account" format:"string"`
	Password string `json:"Password" example:"password" format:"string"`
}

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL