ctxutil

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 13 Imported by: 1

Documentation

Index

Constants

View Source
const (
	TraceIDKey = "trace_id"
)

Variables

This section is empty.

Functions

func EnsureTraceID

func EnsureTraceID(ctx context.Context) (context.Context, string)

EnsureTraceID ensures that a trace ID exists in the context.

func ExtractContext added in v0.1.2

func ExtractContext(payload *map[string]any) context.Context

ExtractContext extracts context from payload map safely

func FromGinContext

func FromGinContext(c *gin.Context) context.Context

FromGinContext extracts the context.Context from *gin.Context.

func GenerateBusinessCode

func GenerateBusinessCode(identifier string) string

GenerateBusinessCode generate business code

format: Code+YYYYMM+AntifakeCODE+Serial, eg: CO2009110GA0001

func GetConfig

func GetConfig(ctx context.Context) *config.Config

GetConfig gets config from context.Context.

func GetEmailSender

func GetEmailSender(ctx context.Context) (email.Sender, error)

GetEmailSender gets email sender from context.Context based on the configured provider

func GetGinContext

func GetGinContext(ctx context.Context) (*gin.Context, bool)

GetGinContext extracts *gin.Context from context.Context if it exists.

func GetProfile

func GetProfile(ctx context.Context) any

GetProfile gets profile from context.Context.

func GetProvider

func GetProvider(ctx context.Context) string

GetProvider gets provider from context.Context.

func GetStorage

func GetStorage(ctx context.Context) (oss.StorageInterface, *storage.Config)

GetStorage gets storage from context.Context

func GetTenantID

func GetTenantID(ctx context.Context) string

GetTenantID gets tenant id from context.Context.

func GetToken

func GetToken(ctx context.Context) string

GetToken gets token from context.Context.

func GetTraceID

func GetTraceID(ctx context.Context) string

GetTraceID gets trace id from context.Context or gin.Context.

func GetUserID

func GetUserID(ctx context.Context) string

GetUserID gets user id from context.Context.

func GetValue

func GetValue(ctx context.Context, key string) any

GetValue retrieves a value from the context.

func SendEmailWithTemplate

func SendEmailWithTemplate(ctx context.Context, recipientEmail string, template email.EmailTemplate) (string, error)

SendEmailWithTemplate sends an email with a template

func SetConfig

func SetConfig(ctx context.Context, conf *config.Config) context.Context

SetConfig sets config to context.Context.

func SetEmailSender

func SetEmailSender(ctx context.Context, sender email.Sender) context.Context

SetEmailSender sets email sender to context.Context

func SetProfile

func SetProfile(ctx context.Context, profile any) context.Context

SetProfile sets profile to context.Context.

func SetProvider

func SetProvider(ctx context.Context, provider string) context.Context

SetProvider sets provider to context.Context.

func SetStorage

SetStorage sets storage to context.Context

func SetTenantID

func SetTenantID(ctx context.Context, uid string) context.Context

SetTenantID sets tenant id to context.Context.

func SetToken

func SetToken(ctx context.Context, token string) context.Context

SetToken sets token to context.Context.

func SetTraceID

func SetTraceID(ctx context.Context, traceID string) context.Context

SetTraceID sets trace id to context.Context and gin.Context if available.

func SetUserID

func SetUserID(ctx context.Context, uid string) context.Context

SetUserID sets user id to context.Context.

func SetValue

func SetValue(ctx context.Context, key string, val any) context.Context

SetValue sets a value to the context.

func WithGinContext

func WithGinContext(ctx context.Context, c *gin.Context) context.Context

WithGinContext returns a context.Context that embeds the *gin.Context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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