Initial commit

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-15 13:57:10 +08:00
co-authored by Claude Opus 5
commit 8679200f41
1897 changed files with 257900 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package elastic
import (
"errors"
"91porn-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
}