Documentation
¶
Index ¶
- Constants
- func EnsureTraceID(ctx context.Context) (context.Context, string)
- func ExtractContext(payload *map[string]any) context.Context
- func FromGinContext(c *gin.Context) context.Context
- func GenerateBusinessCode(identifier string) string
- func GetAcceptLanguage(ctx context.Context) string
- func GetClientIP(ctx context.Context) string
- func GetClientInfo(ctx context.Context) (ip, userAgent, sessionID string)
- func GetConfig(ctx context.Context) *config.Config
- func GetContentType(ctx context.Context) string
- func GetEmailSender(ctx context.Context) (email.Sender, error)
- func GetGinContext(ctx context.Context) (*gin.Context, bool)
- func GetHTTPRequest(ctx context.Context) *http.Request
- func GetHost(ctx context.Context) string
- func GetProfile(ctx context.Context) any
- func GetProvider(ctx context.Context) string
- func GetQueryParams(ctx context.Context) map[string]string
- func GetReferer(ctx context.Context) string
- func GetRemoteAddr(ctx context.Context) string
- func GetRequestHeaders(ctx context.Context) map[string]string
- func GetRequestMethod(ctx context.Context) string
- func GetRequestURI(ctx context.Context) string
- func GetRequestURL(ctx context.Context) string
- func GetSessionID(ctx context.Context) string
- func GetSpaceID(ctx context.Context) string
- func GetStorage(ctx context.Context) (oss.Interface, *oss.Config)
- func GetToken(ctx context.Context) string
- func GetTraceID(ctx context.Context) string
- func GetUserAgent(ctx context.Context) string
- func GetUserEmail(ctx context.Context) string
- func GetUserID(ctx context.Context) string
- func GetUserIsAdmin(ctx context.Context) bool
- func GetUserIsCertified(ctx context.Context) bool
- func GetUserPermissions(ctx context.Context) []string
- func GetUserRoles(ctx context.Context) []string
- func GetUserSpaceIDs(ctx context.Context) []string
- func GetUserStatus(ctx context.Context) int
- func GetUsername(ctx context.Context) string
- func GetValue(ctx context.Context, key string) any
- func IsAjaxRequest(ctx context.Context) bool
- func IsSecureRequest(ctx context.Context) bool
- func SendEmailWithTemplate(ctx context.Context, recipientEmail string, template email.Template) (string, error)
- func SetClientIP(ctx context.Context, ip string) context.Context
- func SetClientInfo(ctx context.Context, ip, userAgent, sessionID string) context.Context
- func SetConfig(ctx context.Context, conf *config.Config) context.Context
- func SetEmailSender(ctx context.Context, sender email.Sender) context.Context
- func SetHTTPRequest(ctx context.Context, req *http.Request) context.Context
- func SetProfile(ctx context.Context, profile any) context.Context
- func SetProvider(ctx context.Context, provider string) context.Context
- func SetReferer(ctx context.Context, referer string) context.Context
- func SetSessionID(ctx context.Context, sessionID string) context.Context
- func SetSpaceID(ctx context.Context, uid string) context.Context
- func SetStorage(ctx context.Context, s oss.Interface) context.Context
- func SetToken(ctx context.Context, token string) context.Context
- func SetTraceID(ctx context.Context, traceID string) context.Context
- func SetUserAgent(ctx context.Context, userAgent string) context.Context
- func SetUserEmail(ctx context.Context, email string) context.Context
- func SetUserID(ctx context.Context, uid string) context.Context
- func SetUserIsAdmin(ctx context.Context, isAdmin bool) context.Context
- func SetUserIsCertified(ctx context.Context, isCertified bool) context.Context
- func SetUserPermissions(ctx context.Context, permissions []string) context.Context
- func SetUserRoles(ctx context.Context, roles []string) context.Context
- func SetUserSpaceIDs(ctx context.Context, spaceIDs []string) context.Context
- func SetUserStatus(ctx context.Context, status int) context.Context
- func SetUsername(ctx context.Context, username string) context.Context
- func SetValue(ctx context.Context, key string, val any) context.Context
- func WithAsyncContext(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
- func WithAsyncContextDefault(parent context.Context) (context.Context, context.CancelFunc)
- func WithGinContext(ctx context.Context, c *gin.Context) context.Context
- type UserAgentInfo
Constants ¶
const ( // DefaultAsyncTimeout is the default timeout for async operations DefaultAsyncTimeout = 5 * time.Second )
const (
TraceIDKey = "trace_id"
)
Variables ¶
This section is empty.
Functions ¶
func EnsureTraceID ¶
EnsureTraceID ensures that a trace ID exists in the context.
func ExtractContext ¶
ExtractContext extracts context from payload map safely
func FromGinContext ¶
FromGinContext extracts the context.Context from *gin.Context.
func GenerateBusinessCode ¶
GenerateBusinessCode generate business code
format: Code+YYYYMM+AntifakeCODE+Serial, eg: CO2009110GA0001
func GetAcceptLanguage ¶
GetAcceptLanguage gets Accept-Language header from context
func GetClientIP ¶
GetClientIP gets client IP from context.Context
func GetClientInfo ¶
GetClientInfo gets all client information from context.Context
func GetContentType ¶
GetContentType gets Content-Type header from context
func GetEmailSender ¶
GetEmailSender gets email sender from context.Context based on the configured provider
func GetGinContext ¶
GetGinContext extracts *gin.Context from context.Context if it exists.
func GetHTTPRequest ¶
GetHTTPRequest gets HTTP request from context.Context
func GetProfile ¶
GetProfile gets profile from context.Context.
func GetProvider ¶
GetProvider gets provider from context.Context.
func GetQueryParams ¶
GetQueryParams gets all query parameters from context
func GetReferer ¶
GetReferer gets HTTP referer from context
func GetRemoteAddr ¶
GetRemoteAddr gets remote address from context
func GetRequestHeaders ¶
GetRequestHeaders gets all request headers from context
func GetRequestMethod ¶
GetRequestMethod gets HTTP method from context
func GetRequestURI ¶
GetRequestURI gets request URI from context
func GetRequestURL ¶
GetRequestURL gets full request URL from context
func GetSessionID ¶
GetSessionID gets session ID from context.Context
func GetSpaceID ¶
GetSpaceID gets space id from context.Context.
func GetTraceID ¶
GetTraceID gets trace id from context.Context or gin.Context.
func GetUserAgent ¶
GetUserAgent gets user agent from context.Context
func GetUserEmail ¶
GetUserEmail gets user email from context.Context.
func GetUserIsAdmin ¶
GetUserIsAdmin gets user admin status from context.Context.
func GetUserIsCertified ¶
GetUserIsCertified gets user is certified from context.Context.
func GetUserPermissions ¶
GetUserPermissions gets user permissions from context.Context.
func GetUserRoles ¶
GetUserRoles gets user roles from context.Context.
func GetUserSpaceIDs ¶
GetUserSpaceIDs gets user space IDs from context.Context.
func GetUserStatus ¶
GetUserStatus gets user status from context.Context.
func GetUsername ¶
GetUsername gets username from context.Context.
func IsAjaxRequest ¶
IsAjaxRequest checks if request is an AJAX request
func IsSecureRequest ¶
IsSecureRequest checks if request is HTTPS
func SendEmailWithTemplate ¶
func SendEmailWithTemplate(ctx context.Context, recipientEmail string, template email.Template) (string, error)
SendEmailWithTemplate sends an email with a template
func SetClientIP ¶
SetClientIP sets client IP to context.Context
func SetClientInfo ¶
SetClientInfo sets client information to context.Context
func SetEmailSender ¶
SetEmailSender sets email sender to context.Context
func SetHTTPRequest ¶
SetHTTPRequest sets HTTP request to context.Context
func SetProfile ¶
SetProfile sets profile to context.Context.
func SetProvider ¶
SetProvider sets provider to context.Context.
func SetReferer ¶
SetReferer sets HTTP referer in context
func SetSessionID ¶
SetSessionID sets session ID to context.Context
func SetSpaceID ¶
SetSpaceID sets space id to context.Context.
func SetTraceID ¶
SetTraceID sets trace id to context.Context and gin.Context if available.
func SetUserAgent ¶
SetUserAgent sets user agent to context.Context
func SetUserEmail ¶
SetUserEmail sets user email to context.Context.
func SetUserIsAdmin ¶
SetUserIsAdmin sets user admin status to context.Context.
func SetUserIsCertified ¶
SetUserIsCertified sets user is certified to context.Context.
func SetUserPermissions ¶
SetUserPermissions sets user permissions to context.Context.
func SetUserRoles ¶
SetUserRoles sets user roles to context.Context.
func SetUserSpaceIDs ¶
SetUserSpaceIDs sets user space IDs to context.Context.
func SetUserStatus ¶
SetUserStatus sets user status to context.Context.
func SetUsername ¶
SetUsername sets username to context.Context.
func WithAsyncContext ¶ added in v0.1.21
func WithAsyncContext(parent context.Context, timeout time.Duration) (context.Context, context.CancelFunc)
WithAsyncContext creates a context suitable for async operations It derives from the parent context to preserve trace information, but uses a separate timeout to avoid blocking the main request
func WithAsyncContextDefault ¶ added in v0.1.21
WithAsyncContextDefault creates an async context with default timeout
Types ¶
type UserAgentInfo ¶
type UserAgentInfo struct {
Browser string `json:"browser"`
Version string `json:"version"`
OS string `json:"os"`
Platform string `json:"platform"`
Mobile bool `json:"mobile"`
}
UserAgentInfo represents parsed user agent information
func GetParsedUserAgent ¶
func GetParsedUserAgent(ctx context.Context) *UserAgentInfo
GetParsedUserAgent gets parsed user agent information from context
func ParseUserAgent ¶
func ParseUserAgent(userAgent string) *UserAgentInfo
ParseUserAgent parses user agent string into structured information