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 ElasticSearch struct {
Cfg define.ComponentEs
Clts map[string]*EsClient
Log logger.Interface
}
func (c *ElasticSearch) CliFlags() []cli.Flag {
fs := make([][]cli.Flag, 0, len(c.Clts)+1)
fs = append(fs, []cli.Flag{
&cli.IntFlag{Name: "es-conn-timeout", Usage: "es connect timeout", Value: 3, Destination: &c.Cfg.MaxConnTime},
&cli.IntFlag{Name: "es-idle-timeout", Usage: "es idle connect timeout", Value: 60, Destination: &c.Cfg.MaxIdleTime},
&cli.IntFlag{Name: "es-req-timeout", Usage: "es request timeout", Value: 15, Destination: &c.Cfg.MaxRepTime},
&cli.IntFlag{Name: "es-keepalive-time", Usage: "es keepalive time", Value: 5, Destination: &c.Cfg.KeepAliveTime},
&cli.IntFlag{Name: "es-threshold", Usage: "es request slow threshold", Value: 300, 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 *ElasticSearch) Init(l logger.Interface, cfg *gsf.AppConfig, _ *cli.Context) error {
c.Log = l
// 打印链接信息
for name, clt := range c.Clts {
clt.Init(cfg.Env(), c)
msg := fmt.Sprintf("Init ElasticSearch (%s) config", name)
if define.PrintfDSN {
msg = fmt.Sprintf("%s (%s)", msg, clt.Config().Addr)
}
c.Log.WarnForce(msg)
}
return nil
}
func (c *ElasticSearch) Run() (err error) {
for name := range c.Clts {
if err = c.LoadOne(name); err != nil {
break
}
}
return err
}
func (c *ElasticSearch) LoadOne(name string) (err error) {
if clt, ok := c.Clts[name]; ok {
err = clt.Load(name)
} else {
err = fmt.Errorf("ElasticSearch (%s) config no find", name)
}
return err
}
func (c *ElasticSearch) Close() error {
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。