Fetch the repository succeeded.
package component
import (
"fmt"
"gitee.com/kzangv/gsf-fof/component/define"
"gitee.com/kzangv/gsf-fof/gsf"
"gitee.com/kzangv/gsf-fof/logger"
"github.com/urfave/cli/v2"
)
type Mongo struct {
Cfg define.ComponentMongo
Clts map[string]*MongoClient
Log logger.Interface
}
func (c *Mongo) CliFlags() []cli.Flag {
fs := make([][]cli.Flag, 0, len(c.Clts)+1)
fs = append(fs, []cli.Flag{
&cli.IntFlag{Name: "mongo-pool-min", Usage: "mongo min pool size", Value: 5, Destination: &c.Cfg.MinPoolSize},
&cli.IntFlag{Name: "mongo-pool-max", Usage: "mongo max pool size", Value: 20, Destination: &c.Cfg.MaxPoolSize},
&cli.IntFlag{Name: "mongo-req-time", Usage: "mongo request timeout", Value: 15, Destination: &c.Cfg.ReqMaxTime},
&cli.IntFlag{Name: "mongo-idle-time", Usage: "mongo idle connect timeout", Value: 60, Destination: &c.Cfg.MaxIdleTime},
&cli.IntFlag{Name: "mongo-selection-time", Usage: "mongo selection timeout", Value: 3, Destination: &c.Cfg.SelectionTime},
&cli.IntFlag{Name: "mongo-threshold", Usage: "mongo slow sql threshold", Value: 100, Destination: &c.Cfg.SlowThreshold},
})
for name, clt := range c.Clts {
fs = append(fs, clt.CliFlags(name))
}
l := 0
for k := range fs {
l += len(fs[k])
}
ret := make([]cli.Flag, 0, l)
for k := range fs {
ret = append(ret, fs[k]...)
}
return ret
}
func (c *Mongo) Init(l logger.Interface, cfg *gsf.AppConfig, ctx *cli.Context) error {
c.Log = l
// 打印链接信息
for k, v := range c.Clts {
v.Init(cfg.Env(), c)
// 打印链接信息
msg := fmt.Sprintf("Init Mongo (%s) config", k)
if define.PrintfDSN {
msg = fmt.Sprintf("%s (%s)", msg, v.Config().DSN)
}
c.Log.WarnForce(msg)
}
return nil
}
func (c *Mongo) Run() error {
for name := range c.Clts {
if err := c.LoadOne(name); err != nil {
return err
}
}
return nil
}
func (c *Mongo) LoadOne(name string) (err error) {
if clt, ok := c.Clts[name]; ok {
err = clt.Load(name)
} else {
err = fmt.Errorf("Mongo (%s) config no find", name)
}
return err
}
func (c *Mongo) Close() error {
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。