Commit 1f5329a9 by zhengqiuyun86

初始化

parent b7c45506
......@@ -73,6 +73,7 @@ var Redis = RedisConf{}
type EsConf struct {
ServerHost string
ServerPort int
Sniff bool
}
var Es = EsConf{}
......
......@@ -20,7 +20,7 @@ func Init() {
host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort)
var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags)
client, err = elastic.NewClient(elastic.SetErrorLog(errorLog), elastic.SetURL(host))
client, err = elastic.NewClient(elastic.SetSniff(conf.Es.Sniff), elastic.SetErrorLog(errorLog), elastic.SetURL(host))
if err != nil {
log.Error(fmt.Sprintf("Elasticsearch connect error:%s", err.Error()))
} else {
......
......@@ -4,7 +4,6 @@ import (
"context"
"fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/olivere/elastic/v7"
_log "log"
......@@ -14,18 +13,21 @@ import (
func init() {
conf.Es = conf.EsConf{
ServerHost: "to-chengdu-office.168cad.top",
ServerPort: 50037,
//ServerHost: "to-chengdu-office.168cad.top",
//ServerPort: 50037,
ServerHost: "192.168.1.124",
ServerPort: 9200,
Sniff: true,
}
}
func TestName(t *testing.T) {
host := "http://to-chengdu-office.168cad.top:50037"
host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort)
var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags)
client, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetErrorLog(errorLog), elastic.SetURL(host))
client, err := elastic.NewClient(elastic.SetSniff(conf.Es.Sniff), elastic.SetErrorLog(errorLog), elastic.SetURL(host))
if err != nil {
exception.ThrowsErrS(fmt.Sprintf("ES连接失败:%s", err.Error()))
log.Error(err.Error())
}
info, code, err := client.Ping(host).Do(context.Background())
if err != nil {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment