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 ) rds := redis.MustNewRedis(redis.RedisConf{ Host: c.RedisConf.Addr, Type: c.RedisConf.Type, Pass: c.RedisConf.Password, Tls: c.RedisConf.Tls, }) {{end}} return &ServiceContext{ Config: c, {{if .isEnt}} DB: db, Redis: rds, {{end}} } }