diff --git a/app/mix/conf/cfg.go b/app/mix/conf/cfg.go index eb67cccd..0d6f77da 100644 --- a/app/mix/conf/cfg.go +++ b/app/mix/conf/cfg.go @@ -21,4 +21,5 @@ type ConfigSt struct { XxlJob *configcenter.XxlJobConfig `json:"xxl_job" yaml:"xxl_job"` // xxl-job作业系统 DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人 VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核 + ElasticSearch *configcenter.ElasticSearchConfig `json:"elastic_search" yaml:"elastic_search"` // es } diff --git a/app/mix/service/service.go b/app/mix/service/service.go index 03ed1555..1992411b 100644 --- a/app/mix/service/service.go +++ b/app/mix/service/service.go @@ -51,6 +51,7 @@ import ( "service/library/contentaudit/imageaudit" "service/library/contentaudit/textaudit" videomoderation "service/library/contentaudit/video_moderation" + elasticsearch "service/library/elastic_search" "service/library/logger" "service/library/melody" "service/library/mycrypto" @@ -151,6 +152,12 @@ func (s *Service) Init(c any) (err error) { logger.Error("cryptoService init, err: %v", err) } + err = elasticsearch.Init(cfg.ElasticSearch) + if err != nil { + logger.Error("elasticsearch.Init fail, cfg: %v, err: %v", util.ToJson(cfg.ElasticSearch), err) + return + } + s.defaultMelody = melody.New() err = alipaycli.InitMulti(cfg.Alipay, cfg.AlipayMYTS) diff --git a/etc/mix/mix-test.yaml b/etc/mix/mix-test.yaml index 9e6c47ed..690d219d 100644 --- a/etc/mix/mix-test.yaml +++ b/etc/mix/mix-test.yaml @@ -137,4 +137,10 @@ xxl_job: ding_talk_robot: access_token: "65f11ade605568c34f33ff79ed4c20c1721bd6da18511d8e08a6ed9666c4b8b4" - secret: "SECcc49257b2681b6488ab4be8ee815c61027a7254e2be3239c229de38b22207b5b" \ No newline at end of file + secret: "SECcc49257b2681b6488ab4be8ee815c61027a7254e2be3239c229de38b22207b5b" + +elastic_search: + uri: "172.31.37.67:9200" + username: "root" + password: "Wishpal@2024" + sniff: false \ No newline at end of file diff --git a/library/configcenter/configcenter.go b/library/configcenter/configcenter.go index fc17114d..dd0a4d98 100644 --- a/library/configcenter/configcenter.go +++ b/library/configcenter/configcenter.go @@ -165,6 +165,14 @@ type XxlJobConfig struct { LogPath string `json:"log_path" yaml:"log_path"` } +// elasticsearch服务配置 +type ElasticSearchConfig struct { + Uri string `json:"uri" yaml:"uri"` // 实例地址 + Username string `json:"username" yaml:"username"` // 用户名 + Password string `json:"password" yaml:"password"` // 密码 + Sniff bool `json:"sniff" yaml:"sniff"` +} + func LoadConfig(configFilePath string, cfg interface{}) error { cfgStr, err := ioutil.ReadFile(configFilePath) if err != nil { diff --git a/library/elastic_search/client.go b/library/elastic_search/client.go index 0f5721c6..f0eaaf86 100644 --- a/library/elastic_search/client.go +++ b/library/elastic_search/client.go @@ -1,9 +1,24 @@ package elasticsearch import ( + "service/bizcommon/util" + "service/library/configcenter" + "service/library/logger" + "github.com/olivere/elastic/v7" ) -func NewElasticSearchClient() { - elastic.NewClient() +var defaultElasticSearchClient *elastic.Client + +func Init(cfg *configcenter.ElasticSearchConfig) (err error) { + defaultElasticSearchClient, err = elastic.NewClient( + elastic.SetURL(cfg.Uri), + elastic.SetSniff(cfg.Sniff), + elastic.SetBasicAuth(cfg.Username, cfg.Password), + ) + if err != nil { + logger.Error("NewElasticSearchClient fail, cfg: %v, err: %v", util.ToJson(cfg), err) + return + } + return }