1 Star 0 Fork 0

kzangv/gsf-fof

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
elastic.go 1.94 KB
Copy Edit Raw Blame History
kzangv authored 2023-03-15 16:15 . fixed
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
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/kzangv/gsf-fof.git
git@gitee.com:kzangv/gsf-fof.git
kzangv
gsf-fof
gsf-fof
v0.4.3

Search