Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rym-util
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhengqiuyun
rym-util
Commits
1f5329a9
Commit
1f5329a9
authored
Aug 17, 2022
by
zhengqiuyun86
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
初始化
parent
b7c45506
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
7 deletions
+10
-7
conf.go
conf/conf.go
+1
-0
EsClient.go
es/EsClient.go
+1
-1
EsLogger_test.go
es/EsLogger_test.go
+8
-6
No files found.
conf/conf.go
View file @
1f5329a9
...
@@ -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
{}
...
...
es/EsClient.go
View file @
1f5329a9
...
@@ -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
.
Set
Sniff
(
conf
.
Es
.
Sniff
),
elastic
.
Set
ErrorLog
(
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
{
...
...
es/EsLogger_test.go
View file @
1f5329a9
...
@@ -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
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment