Commit 1f5329a9 by zhengqiuyun86

初始化

parent b7c45506
...@@ -73,6 +73,7 @@ var Redis = RedisConf{} ...@@ -73,6 +73,7 @@ var Redis = RedisConf{}
type EsConf struct { type EsConf struct {
ServerHost string ServerHost string
ServerPort int ServerPort int
Sniff bool
} }
var Es = EsConf{} var Es = EsConf{}
......
...@@ -20,7 +20,7 @@ func Init() { ...@@ -20,7 +20,7 @@ func Init() {
host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort) host := fmt.Sprintf("http://%s:%d", conf.Es.ServerHost, conf.Es.ServerPort)
var err error var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags) 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 { if err != nil {
log.Error(fmt.Sprintf("Elasticsearch connect error:%s", err.Error())) log.Error(fmt.Sprintf("Elasticsearch connect error:%s", err.Error()))
} else { } else {
......
...@@ -4,7 +4,6 @@ import ( ...@@ -4,7 +4,6 @@ import (
"context" "context"
"fmt" "fmt"
"git.168cad.top/zhengqiuyun/rym-util/conf" "git.168cad.top/zhengqiuyun/rym-util/conf"
"git.168cad.top/zhengqiuyun/rym-util/exception"
"git.168cad.top/zhengqiuyun/rym-util/log" "git.168cad.top/zhengqiuyun/rym-util/log"
"github.com/olivere/elastic/v7" "github.com/olivere/elastic/v7"
_log "log" _log "log"
...@@ -14,18 +13,21 @@ import ( ...@@ -14,18 +13,21 @@ import (
func init() { func init() {
conf.Es = conf.EsConf{ conf.Es = conf.EsConf{
ServerHost: "to-chengdu-office.168cad.top", //ServerHost: "to-chengdu-office.168cad.top",
ServerPort: 50037, //ServerPort: 50037,
ServerHost: "192.168.1.124",
ServerPort: 9200,
Sniff: true,
} }
} }
func TestName(t *testing.T) { 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 var err error
errorLog := _log.New(os.Stdout, "APP", _log.LstdFlags) 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 { if err != nil {
exception.ThrowsErrS(fmt.Sprintf("ES连接失败:%s", err.Error())) log.Error(err.Error())
} }
info, code, err := client.Ping(host).Do(context.Background()) info, code, err := client.Ping(host).Do(context.Background())
if err != nil { 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