This commit is contained in:
yun
2024-07-09 20:05:53 +08:00
parent 570d7cc0f7
commit 3e2c5daf3e
2 changed files with 25 additions and 0 deletions
+11
View File
@@ -4,6 +4,7 @@ type options struct {
defaultCode int
defaultLang string
replaceKey string
ctxLangKey string
}
func defaultOptions() *options {
@@ -11,6 +12,7 @@ func defaultOptions() *options {
defaultCode: 200,
defaultLang: "zh",
replaceKey: "#%s#",
ctxLangKey: "language",
}
}
@@ -22,12 +24,21 @@ func SetDefaultCode(code int) Option {
}
}
// 从ctx里面获取语言的key
func SetCtxLangKey(key string) Option {
return func(o *options) {
o.ctxLangKey = key
}
}
// 默认语言
func SetDefaultLanguage(lang string) Option {
return func(o *options) {
o.defaultLang = lang
}
}
// 替换规则 %s 为占位符
func SetReplaceKey(key string) Option {
return func(o *options) {
o.replaceKey = key