httpx

package
v0.0.0-...-a89d057 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
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 DebouceAw

func DebouceAw(path ...string)

func Debounce

func Debounce(duration time.Duration) gin.HandlerFunc

func DebounceAllow

func DebounceAllow(path ...string)

func DebounceDisable

func DebounceDisable()

func DumpRouters

func DumpRouters(call func(info gin.RouteInfo))

func FetchImage

func FetchImage(url string) (imgData []byte, contentType, imgType string, error *errors.Error)

FetchImage fetches image bytes and MIME type from URL.

func Get

func Get(baseURL string, params map[string]string) (resp string, err *errors.Error)

Get sends GET request and returns raw response string.

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 GetClientIP(ctx *gin.Context) string

Deprecated: Use apix.GetClientIP() instead.

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 GetMap

func GetMap(baseURL string, params map[string]string) (map[string]interface{}, *errors.Error)

GetMap performs GET request returning parsed map.

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 GetToken

func GetToken(c *gin.Context) string

func GetTokenByCtx

func GetTokenByCtx(c *gin.Context, mustExit bool) string

GetTokenByCtx

func GetTraceID deprecated

func GetTraceID(ctx *gin.Context) string

Deprecated: Use apix.GetTraceID() instead.

func GetUserID deprecated

func GetUserID(ctx *gin.Context) string

Deprecated: Use apix.GetUserID() instead.

func GetUserIDByToken

func GetUserIDByToken(token string) (userID string)

func GetUserIDInt deprecated

func GetUserIDInt(ctx *gin.Context) int

Deprecated: Use apix.GetUserIDInt() instead.

func GetUserIDInt64 deprecated

func GetUserIDInt64(ctx *gin.Context) int64

Deprecated: Use apix.GetUserIDInt64() instead.

func GetUserInfo deprecated

func GetUserInfo(ctx *gin.Context) map[string]interface{}

Deprecated: Use apix.GetUserInfo() instead.

func GetUserInfoValue deprecated

func GetUserInfoValue(ctx *gin.Context, key string) any

Deprecated: Use apix.GetUserInfoValue() instead.

func IsRegistered

func IsRegistered() bool

func Logger

func Logger() gin.HandlerFunc

func NewCtx deprecated

func NewCtx() *gin.Context

Deprecated: Use apix.NewCtx() instead.

func ParseJSON

func ParseJSON(jsonStr string) map[string]interface{}

ParseJSON parses a JSON string into map[string]interface{}.

func ParseXML

func ParseXML[T any](xmlStr string) (*T, *errors.Error)

ParseXML parses XML string into struct *T.

func Post

func Post[T any](baseURL string, body any, header ...map[string]string) (*T, *errors.Error)

Post sends a JSON POST request and unmarshals response into *T.

func PostForm

func PostForm(baseURL string, params map[string]string) (resp string, err *errors.Error)

PostForm performs form POST request.

func PostJSON

func PostJSON(baseURL string, params interface{}) (map[string]interface{}, *errors.Error)

PostJSON performs JSON POST returning parsed map.

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

func PostJSONResp(baseURL string, params interface{}) (resp string, err *errors.Error)

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 PostXML

func PostXML(baseURL string, params map[string]string) (resp string, err *errors.Error)

PostXML sends XML POST request.

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

func SetTimeOutTmp(t time.Duration)

SetTimeOutTmp sets temporary client timeout for duration t.

func SetTraceID deprecated

func SetTraceID(ctx *gin.Context)

Deprecated: Use apix.SetTraceID() instead.

func SetUserID deprecated

func SetUserID(ctx *gin.Context, userID string)

Deprecated: Use apix.SetUserID() instead.

func SetUserInfo deprecated

func SetUserInfo(ctx *gin.Context, userInfo map[string]interface{})

Deprecated: Use apix.SetUserInfo() instead.

func Shutdown

func Shutdown(code string, ctx context.Context) error

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

func Startup

func Startup(code, port string) error

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.

func (*ShardedRequestMap) Get

func (srm *ShardedRequestMap) Get(key string) (time.Time, bool)

func (*ShardedRequestMap) Set

func (srm *ShardedRequestMap) Set(key string, value time.Time)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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