Documentation
¶
Index ¶
- Constants
- func BasicAuth(username, password string, handle func(*gin.Context, string)) gin.HandlerFunc
- func BasicBcrypt(username, password string, handle func(*gin.Context, ...string)) gin.HandlerFunc
- func CacheControl(seconds int) gin.HandlerFunc
- func Cors(origins []string, maxAges ...time.Duration) gin.HandlerFunc
- func Cors0(origin string, methods string) gin.HandlerFunc
- func Get[T any](ctx *gin.Context, key string) (item T, err error)
- func GetAPI(ctx *gin.Context) string
- func GetDate(ctx *gin.Context) (*time.Time, error)
- func Healthz(ctx *gin.Context)
- func IndexStaticFiles(router *gin.RouterGroup, d string) (err error)
- func JSONStatic(data any) gin.HandlerFunc
- func NewAPILog(logger Logger[zap.Field], debug bool, errorHandler func(*gin.Context) []string, ...) (hf gin.HandlerFunc)
- func PromHandler() gin.HandlerFunc
- func ResponseFile(ctx *gin.Context, buf *bytes.Buffer, filename, typ string)
- func ServeStaticDir(httpDir, local string, listDir bool) func(*gin.RouterGroup)
- func ServeStaticFS(rg *gin.RouterGroup, efs embed.FS, p string, secs int) (err error)
- func ServeStaticFile(bts []byte, name string) gin.HandlerFunc
- func SetData(ctx *gin.Context, kvs map[string]any)
- func SetError(ctx *gin.Context, err any)
- func SetKV(ctx *gin.Context, key string, value any)
- func SetRequestId(ctx *gin.Context, requestId string)
- func Validate[T any](item *T) (err error)
- func WsUpgrade(ctx *gin.Context)
- type HttpConfig
- type JwtData
- type JwtHMAC
- type Logger
Constants ¶
View Source
const ( GIN_RequestId = "GIN_RequestId" GIN_Error = "GIN_Error" GIN_AccountId = "GIN_AccountId" // string GIN_Data = "GIN_Data" // map[string]any )
Variables ¶
This section is empty.
Functions ¶
func BasicBcrypt ¶
handle key: no_token, invalid_token, incorrect_token, User:XXXX
func CacheControl ¶
func CacheControl(seconds int) gin.HandlerFunc
func Cors ¶
func Cors(origins []string, maxAges ...time.Duration) gin.HandlerFunc
HTTP/1.1 204 No Content Access-Control-Allow-Credentials: true Access-Control-Allow-Headers: Origin,Content-Type,Authorization Access-Control-Allow-Methods: GET,POST,OPTIONS,HEAD Access-Control-Allow-Origin: http://localhost:5173 Access-Control-Max-Age: 3600 Vary: Origin Vary: Access-Control-Request-Method Vary: Access-Control-Request-Headers Date: Thu, 08 Aug 2024 00:18:50 GMT
func IndexStaticFiles ¶
func IndexStaticFiles(router *gin.RouterGroup, d string) (err error)
func JSONStatic ¶
func JSONStatic(data any) gin.HandlerFunc
func ServeStaticDir ¶
func ServeStaticDir(httpDir, local string, listDir bool) func(*gin.RouterGroup)
func ServeStaticFile ¶
func ServeStaticFile(bts []byte, name string) gin.HandlerFunc
name: filename, e.g. favicon.ico ct: Content-Type, e.g. image/x-icon
func SetRequestId ¶
Types ¶
type HttpConfig ¶
type HttpConfig struct { Path string `mapstructure:"path"` AllowOrigins []string `mapstructure:"allow_origins"` Tls bool `mapstructure:"tls"` Cert string `mapstructure:"cert"` Key string `mapstructure:"key"` }
func (*HttpConfig) FromFile ¶
func (self *HttpConfig) FromFile(fp string) (err error)
func (*HttpConfig) SetEngine ¶
func (self *HttpConfig) SetEngine(engine *gin.Engine)
type JwtData ¶
type JwtData struct { Issuer string `json:"iss"` // required: *app_name Subject string `json:"sub"` // required: *account_id Audience []string `json:"aud,omitempty"` IssuedAt int64 `json:"iat"` // required: ExpiresAt int64 `json:"exp"` // required: NotBefore int64 `json:"nbf,omitempty"` ID string `json:"jti"` // required: *request_id Data map[string]string `json:"_data"` }
see jwt.RegisteredClaims
type JwtHMAC ¶
type JwtHMAC struct { Key string `mapstructure:"key"` Interval time.Duration `mapstructure:"interval"` // dynamic refresh token ttl in cache Duration time.Duration `mapstructure:"duration"` Method uint `mapstructure:"method"` // contains filtered or unexported fields }
func (*JwtHMAC) ParsePayload ¶
Click to show internal directories.
Click to hide internal directories.