You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1016 B
Smarty

package svc
import (
{{.imports}}
"github.com/zeromicro/go-zero/core/logx"
"git.noahlan.cn/noahlan/ntool/nlog"
"git.noahlan.cn/noahlan/ntool-biz/zero/logz"
"git.noahlan.cn/noahlan/ntool-biz/core/i18n"
)
type ServiceContext struct {
Config config.Config
{{if .isEnt}}
DB *ent.Client
Redis *redis.Redis
{{end}}
}
func NewServiceContext(c config.Config) *ServiceContext {
nlog.MustSetup(logz.WrapConf(c.Log))
logx.SetWriter(logz.NewWriter())
//
i18n.InitWithConfig(c.I18nConf)
{{if .isEnt}}
db := ent.NewClient(
ent.Log(nlog.Info), // logger
ent.Driver(c.DatabaseConf.NewNoCacheDriver()),
ent.Debug(), // debug mode
)
{{end}}
rds := redis.MustNewRedis(redis.RedisConf{
Host: c.RedisConf.Addr,
Type: c.RedisConf.Type,
Pass: c.RedisConf.Password,
Tls: c.RedisConf.Tls,
})
return &ServiceContext{
Config: c,
{{if .isEnt}}
DB: db,
Redis: rds,
{{end}}
}
}