初始化项目框架,完成部分接口开发
This commit is contained in:
20
internal/middleware/language.go
Normal file
20
internal/middleware/language.go
Normal file
@ -0,0 +1,20 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"server/utility/i18n"
|
||||
|
||||
"github.com/gogf/gf/v2/net/ghttp"
|
||||
)
|
||||
|
||||
// Language 语言检测中间件
|
||||
// 从请求头或查询参数中检测语言设置,并设置到上下文中
|
||||
func Language(r *ghttp.Request) {
|
||||
// 获取语言设置
|
||||
lang := i18n.GetLanguage(r.GetCtx())
|
||||
|
||||
// 将语言设置到上下文中,供后续使用
|
||||
r.SetCtxVar("language", lang)
|
||||
|
||||
// 继续下一个中间件
|
||||
r.Middleware.Next()
|
||||
}
|
||||
Reference in New Issue
Block a user