Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-socketCenter
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
hujiebin
hilo-socketCenter
Commits
766ed27e
Commit
766ed27e
authored
Oct 23, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:去掉consul
parent
587cdf55
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
16 deletions
+12
-16
main.go
main.go
+12
-16
No files found.
main.go
View file @
766ed27e
...
@@ -6,13 +6,11 @@ import (
...
@@ -6,13 +6,11 @@ import (
"fmt"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/proto"
"github.com/hashicorp/consul/api"
"google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/keepalive"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
"google.golang.org/grpc/resolver/manual"
"hilo-socketCenter/common"
"hilo-socketCenter/common"
"hilo-socketCenter/common/consul"
"hilo-socketCenter/common/dingding"
"hilo-socketCenter/common/dingding"
"hilo-socketCenter/common/mylogrus"
"hilo-socketCenter/common/mylogrus"
"hilo-socketCenter/common/redisCli"
"hilo-socketCenter/common/redisCli"
...
@@ -43,24 +41,22 @@ var kacp = keepalive.ClientParameters{
...
@@ -43,24 +41,22 @@ var kacp = keepalive.ClientParameters{
// 初始化userCenterClient
// 初始化userCenterClient
func
init
()
{
func
init
()
{
client
,
err
:=
api
.
NewClient
(
api
.
DefaultConfig
())
//非默认情况下需要设置实际的参数
redisKey
:=
fmt
.
Sprintf
(
"service:userCenter"
)
ipPorts
,
err
:=
redisCli
.
GetRedisCluster
()
.
ZRangeByScore
(
context
.
Background
(),
redisKey
,
&
redis
.
ZRangeBy
{
Min
:
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
Add
(
-
time
.
Second
*
15
)
.
Unix
()),
// 3倍心跳
Max
:
"+inf"
,
})
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
mylogrus
.
MyLog
.
Fatalln
(
err
)
failMsg
:=
fmt
.
Sprintf
(
"get service fail,svc:%v,err:%v"
,
"userCenter"
,
err
)
mylogrus
.
MyLog
.
Errorf
(
failMsg
)
}
else
if
len
(
ipPorts
)
>
0
{
}
}
cataLog
:=
client
.
Catalog
()
if
len
(
ipPorts
)
<=
0
{
if
cataLog
==
nil
{
ipPorts
=
[]
string
{
"127.0.0.1:50040"
}
mylogrus
.
MyLog
.
Fatalln
(
"No catalog."
)
}
addr
,
err
:=
consul
.
GetServices
(
cataLog
,
"userCenter"
)
if
err
!=
nil
{
mylogrus
.
MyLog
.
Fatalln
(
err
)
}
if
len
(
addr
)
==
0
{
mylogrus
.
MyLog
.
Fatalln
(
"No userCenter available."
)
}
}
addresses
:=
make
([]
resolver
.
Address
,
len
(
addr
))
addresses
:=
make
([]
resolver
.
Address
,
len
(
ipPorts
))
for
i
,
s
:=
range
addr
{
for
i
,
s
:=
range
ipPorts
{
addresses
[
i
]
.
Addr
=
s
addresses
[
i
]
.
Addr
=
s
mylogrus
.
MyLog
.
Infof
(
"address : %s"
,
s
)
mylogrus
.
MyLog
.
Infof
(
"address : %s"
,
s
)
}
}
...
...
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