Documentation
¶
Index ¶
- Constants
- func CORS() gin.HandlerFunc
- func DebouceAw(path ...string)
- func Debounce(duration time.Duration) gin.HandlerFunc
- func DebounceAllow(path ...string)
- func DebounceDisable()
- func DumpRouters(call func(info gin.RouteInfo))
- func FetchImage(url string) (imgData []byte, contentType, imgType string, error *errors.Error)
- func Get(baseURL string, params map[string]string) (resp string, err *errors.Error)
- func GetByCtx(ctx *gin.Context, baseURL string, params map[string]interface{}) (map[string]interface{}, *errors.Error)
- func GetClientIP(ctx *gin.Context) stringdeprecated
- func GetHeader(baseURL string, params map[string]string, header map[string]string) (resp string, err *errors.Error)
- func GetJSON[T any](baseURL string, params map[string]string, header ...map[string]string) (*T, *errors.Error)
- func GetMap(baseURL string, params map[string]string) (map[string]interface{}, *errors.Error)
- func GetMapHeader(baseURL string, params map[string]string, header map[string]string) (map[string]interface{}, *errors.Error)
- func GetToken(c *gin.Context) string
- func GetTokenByCtx(c *gin.Context, mustExit bool) string
- func GetTraceID(ctx *gin.Context) stringdeprecated
- func GetUserID(ctx *gin.Context) stringdeprecated
- func GetUserIDByToken(token string) (userID string)
- func GetUserIDInt(ctx *gin.Context) intdeprecated
- func GetUserIDInt64(ctx *gin.Context) int64deprecated
- func GetUserInfo(ctx *gin.Context) map[string]interface{}deprecated
- func GetUserInfoValue(ctx *gin.Context, key string) anydeprecated
- func IsRegistered() bool
- func Logger() gin.HandlerFunc
- func NewCtx() *gin.Contextdeprecated
- func ParseJSON(jsonStr string) map[string]interface{}
- func ParseXML[T any](xmlStr string) (*T, *errors.Error)
- func Post[T any](baseURL string, body any, header ...map[string]string) (*T, *errors.Error)
- func PostForm(baseURL string, params map[string]string) (resp string, err *errors.Error)
- func PostJSON(baseURL string, params interface{}) (map[string]interface{}, *errors.Error)
- func PostJSONByCtx(ctx *gin.Context, baseURL string, params interface{}) (map[string]interface{}, *errors.Error)
- func PostJSONHeader(baseURL string, params interface{}, header map[string]string) (map[string]interface{}, *errors.Error)
- func PostJSONResp(baseURL string, params interface{}) (resp string, err *errors.Error)
- func PostJSONRespHeader(baseURL string, params interface{}, header map[string]string) (resp string, err *errors.Error)
- func PostXML(baseURL string, params map[string]string) (resp string, err *errors.Error)
- func Recovery() gin.HandlerFunc
- func RegisterRouter(reg func(groupRouter *gin.RouterGroup))
- func RegisterRouterMid(...) *gin.RouterGroup
- func SetAllowedOrigins(origins ...string)
- func SetOtherAllowHeaders(headers ...string)
- func SetTimeOutTmp(t time.Duration)
- func SetTraceID(ctx *gin.Context)deprecated
- func SetUserID(ctx *gin.Context, userID string)deprecated
- func SetUserInfo(ctx *gin.Context, userInfo map[string]interface{})deprecated
- func Shutdown(code string, ctx context.Context) error
- func SignDef() gin.HandlerFunc
- func SignRedis() gin.HandlerFunc
- func SignUserDef(userFilter map[string]interface{}) gin.HandlerFunc
- func SignUserRedis(userFilter map[string]interface{}) gin.HandlerFunc
- func Startup(code, port string) error
- type HeaderParams
- type ShardedRequestMap
Constants ¶
const ( AllowMethods = "GET, POST, PUT, DELETE, OPTIONS" AllowHeaders = "" + "Origin, " + "Content-Type, " + "Content-Length, " + "Accept-Encoding, " + "X-CSRF-Token, " + "X-Request-ID, " + "Authorization, " )
Variables ¶
This section is empty.
Functions ¶
func CORS ¶
func CORS() gin.HandlerFunc
func DebounceAllow ¶
func DebounceAllow(path ...string)
func DebounceDisable ¶
func DebounceDisable()
func DumpRouters ¶
func FetchImage ¶
FetchImage fetches image bytes and MIME type from URL.
func GetByCtx ¶
func GetByCtx(ctx *gin.Context, baseURL string, params map[string]interface{}) (map[string]interface{}, *errors.Error)
GetByCtx copies Authorization header from gin context and sends GET.
func GetClientIP
deprecated
func GetHeader ¶
func GetHeader(baseURL string, params map[string]string, header map[string]string) (resp string, err *errors.Error)
GetHeader sends GET request with custom headers.
func GetJSON ¶
func GetJSON[T any](baseURL string, params map[string]string, header ...map[string]string) (*T, *errors.Error)
GetJSON performs a GET request and unmarshals the JSON response into *T.
func GetMapHeader ¶
func GetMapHeader(baseURL string, params map[string]string, header map[string]string) (map[string]interface{}, *errors.Error)
GetMapHeader performs GET request with headers returning parsed map.
func GetTraceID
deprecated
func GetUserIDByToken ¶
func GetUserIDInt
deprecated
func GetUserIDInt64
deprecated
func GetUserInfo
deprecated
func GetUserInfoValue
deprecated
func IsRegistered ¶
func IsRegistered() bool
func Logger ¶
func Logger() gin.HandlerFunc
func PostJSONByCtx ¶
func PostJSONByCtx(ctx *gin.Context, baseURL string, params interface{}) (map[string]interface{}, *errors.Error)
PostJSONByCtx copies Authorization header from gin context and sends JSON POST.
func PostJSONHeader ¶
func PostJSONHeader(baseURL string, params interface{}, header map[string]string) (map[string]interface{}, *errors.Error)
PostJSONHeader performs JSON POST with headers returning parsed map.
func PostJSONResp ¶
PostJSONResp performs JSON POST returning response body string.
func PostJSONRespHeader ¶
func PostJSONRespHeader(baseURL string, params interface{}, header map[string]string) (resp string, err *errors.Error)
PostJSONRespHeader performs JSON POST with custom headers returning response string.
func Recovery ¶
func Recovery() gin.HandlerFunc
func RegisterRouter ¶
func RegisterRouter(reg func(groupRouter *gin.RouterGroup))
RegisterRouter 注册路由
func RegisterRouterMid ¶
func RegisterRouterMid(group func(groupRouter *gin.RouterGroup, mid ...gin.HandlerFunc) *gin.RouterGroup, mid ...gin.HandlerFunc) *gin.RouterGroup
func SetAllowedOrigins ¶
func SetAllowedOrigins(origins ...string)
SetAllowedOrigins configures exact origins. Passing "*" allows public, non-credentialed cross-origin requests.
func SetOtherAllowHeaders ¶
func SetOtherAllowHeaders(headers ...string)
func SetTimeOutTmp ¶
SetTimeOutTmp sets temporary client timeout for duration t.
func SetTraceID
deprecated
func SetUserInfo
deprecated
func SignDef ¶
func SignDef() gin.HandlerFunc
func SignRedis ¶
func SignRedis() gin.HandlerFunc
func SignUserDef ¶
func SignUserDef(userFilter map[string]interface{}) gin.HandlerFunc
func SignUserRedis ¶
func SignUserRedis(userFilter map[string]interface{}) gin.HandlerFunc
Types ¶
type HeaderParams ¶
type HeaderParams struct {
Authorization string `header:"Authorization" binding:"required,min=20"`
}
type ShardedRequestMap ¶
type ShardedRequestMap struct {
// contains filtered or unexported fields
}
func NewShardedRequestMap ¶
func NewShardedRequestMap() *ShardedRequestMap
func (*ShardedRequestMap) Allow ¶
func (srm *ShardedRequestMap) Allow(key string, now time.Time, duration time.Duration) (last time.Time, allowed bool)
Allow atomically checks the last request and records the current time. A separate Get followed by Set lets concurrent requests pass the debounce window together.