by Robin at 20240510

This commit is contained in:
Leufolium 2024-05-10 18:11:36 +08:00
parent c13973cd60
commit d1fcc7da5c
5 changed files with 40 additions and 3 deletions

View File

@ -21,4 +21,5 @@ type ConfigSt struct {
XxlJob *configcenter.XxlJobConfig `json:"xxl_job" yaml:"xxl_job"` // xxl-job作业系统 XxlJob *configcenter.XxlJobConfig `json:"xxl_job" yaml:"xxl_job"` // xxl-job作业系统
DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人 DingTalkRobot *configcenter.DingTalkRobotConfig `json:"ding_talk_robot" yaml:"ding_talk_robot"` // 钉钉机器人
VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核 VideoModeration *configcenter.VideoModerationConfig `json:"video_moderation" yaml:"video_moderation"` // 视频审核
ElasticSearch *configcenter.ElasticSearchConfig `json:"elastic_search" yaml:"elastic_search"` // es
} }

View File

@ -51,6 +51,7 @@ import (
"service/library/contentaudit/imageaudit" "service/library/contentaudit/imageaudit"
"service/library/contentaudit/textaudit" "service/library/contentaudit/textaudit"
videomoderation "service/library/contentaudit/video_moderation" videomoderation "service/library/contentaudit/video_moderation"
elasticsearch "service/library/elastic_search"
"service/library/logger" "service/library/logger"
"service/library/melody" "service/library/melody"
"service/library/mycrypto" "service/library/mycrypto"
@ -151,6 +152,12 @@ func (s *Service) Init(c any) (err error) {
logger.Error("cryptoService init, err: %v", err) 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() s.defaultMelody = melody.New()
err = alipaycli.InitMulti(cfg.Alipay, cfg.AlipayMYTS) err = alipaycli.InitMulti(cfg.Alipay, cfg.AlipayMYTS)

View File

@ -137,4 +137,10 @@ xxl_job:
ding_talk_robot: ding_talk_robot:
access_token: "65f11ade605568c34f33ff79ed4c20c1721bd6da18511d8e08a6ed9666c4b8b4" access_token: "65f11ade605568c34f33ff79ed4c20c1721bd6da18511d8e08a6ed9666c4b8b4"
secret: "SECcc49257b2681b6488ab4be8ee815c61027a7254e2be3239c229de38b22207b5b" secret: "SECcc49257b2681b6488ab4be8ee815c61027a7254e2be3239c229de38b22207b5b"
elastic_search:
uri: "172.31.37.67:9200"
username: "root"
password: "Wishpal@2024"
sniff: false

View File

@ -165,6 +165,14 @@ type XxlJobConfig struct {
LogPath string `json:"log_path" yaml:"log_path"` 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 { func LoadConfig(configFilePath string, cfg interface{}) error {
cfgStr, err := ioutil.ReadFile(configFilePath) cfgStr, err := ioutil.ReadFile(configFilePath)
if err != nil { if err != nil {

View File

@ -1,9 +1,24 @@
package elasticsearch package elasticsearch
import ( import (
"service/bizcommon/util"
"service/library/configcenter"
"service/library/logger"
"github.com/olivere/elastic/v7" "github.com/olivere/elastic/v7"
) )
func NewElasticSearchClient() { var defaultElasticSearchClient *elastic.Client
elastic.NewClient()
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
} }