Files
be.ems/src/modules/common/controller/common.go
2023-12-12 19:35:04 +08:00

72 lines
1.6 KiB
Go

package controller
import (
"ems.agt/src/framework/i18n"
"ems.agt/src/framework/utils/ctx"
"ems.agt/src/framework/vo/result"
commonService "ems.agt/src/modules/common/service"
"github.com/gin-gonic/gin"
)
// 实例化控制层 CommontController 结构体
var NewCommont = &CommontController{
commontService: commonService.NewCommontImpl,
}
// 通用请求
//
// PATH /
type CommontController struct {
// 通用请求服务
commontService commonService.ICommont
}
// 哈希加密
//
// POST /hash
func (s *CommontController) Hash(c *gin.Context) {
c.String(200, "commont Hash")
}
// 多语言处理
//
// GET /i18n
func (s *CommontController) I18n(c *gin.Context) {
language := ctx.AcceptLanguage(c)
i18nLang := i18n.TKey(language, "i18n")
hello := i18n.TKey(language, "hello")
ivs := i18n.TTemplate(language, "errorFields", nil)
errorFields := i18n.TTemplate(language, "errorFields", map[string]any{
"num": 1000,
"hello": "你好",
"h2o2": false,
"fileName": " ====",
})
c.JSON(200, map[string]any{
"lang": language,
"i18nLang": i18nLang,
"ivs": ivs,
"hello": hello,
"errorFields": errorFields,
})
}
// 系统可暴露的配置信息
//
// GET /sys-conf
func (s *CommontController) SysConfig(c *gin.Context) {
data := s.commontService.SystemConfigInfo()
// 闭包函数处理多语言
language := ctx.AcceptLanguage(c)
converI18n := func(language string, arr *map[string]string) {
for k, v := range *arr {
(*arr)[k] = i18n.TKey(language, v)
}
}
converI18n(language, &data)
c.JSON(200, result.OkData(data))
}