init: hgmj server initial commit

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-10-08 16:50:13 +08:00
co-authored by Claude Opus 4.7
commit 625e89c15d
1870 changed files with 254090 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package elastic
import (
"errors"
"91jd-server/common/log"
"github.com/elastic/go-elasticsearch/v8"
)
var esClient *Client
// Client 获取elastic客户端
func InitElastic(opt Options) (*Client, error) {
if len(opt.Address) == 0 {
return nil, errors.New("elasticSearch address is empty")
}
cfg := elasticsearch.Config{
Addresses: opt.Address,
Username: opt.UserName,
Password: opt.PassWord,
}
es, err := elasticsearch.NewClient(cfg)
if err != nil {
log.Error("create elasticSearch client occour error", log.E(err))
return nil, err
}
esClient = &Client{Client: es}
if err = esClient.Ping(); err != nil {
log.Warn("elasticSarch ping failed", log.E(err))
return nil, err
}
log.Info("init elasticSearch successful")
return esClient, nil
}
func Init() *Client {
return esClient
}