mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-28 07:05:19 +08:00
23 lines
421 B
Go
23 lines
421 B
Go
package i18n
|
|
|
|
import "context"
|
|
|
|
type CtxKey string
|
|
|
|
const (
|
|
LangKey CtxKey = "lang"
|
|
)
|
|
|
|
// NewCtxWithLang 将lang放置context中
|
|
func NewCtxWithLang(ctx context.Context, lang string) context.Context {
|
|
return context.WithValue(ctx, LangKey, lang)
|
|
}
|
|
|
|
// GetLangFromCtx 从context中获取lang
|
|
func GetLangFromCtx(ctx context.Context) string {
|
|
if val, ok := ctx.Value(LangKey).(string); ok {
|
|
return val
|
|
}
|
|
return ""
|
|
}
|