Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gomicro-base
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
lizifeng
gomicro-base
Commits
80839e9e
Commit
80839e9e
authored
Jun 14, 2022
by
kzkzzzz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 调整client
parent
9d5884e0
Pipeline
#1362
failed with stages
Changes
11
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
29 additions
and
53 deletions
+29
-53
config.yaml
service/demo/config/config.yaml
+1
-1
conf.go
service/demo/internal/conf/conf.go
+4
-4
grpc.go
service/demo/internal/server/grpc.go
+2
-2
config.yaml
service/member/config/config.yaml
+1
-1
conf.go
service/member/internal/conf/conf.go
+4
-4
grpc.go
service/member/internal/server/grpc.go
+2
-2
client.go
service/wallet/client/client.go
+7
-25
config.yaml
service/wallet/config/config.yaml
+1
-1
conf.go
service/wallet/internal/conf/conf.go
+4
-4
grpc.go
service/wallet/internal/server/grpc.go
+2
-2
gateway.go
tool/gateway/gateway.go
+1
-7
No files found.
service/demo/config/config.yaml
View file @
80839e9e
Server
:
Name
:
"
service.demo"
Consul
Serve
r
:
Consul
Add
r
:
-
192.168.233.1:8500
Grpc
:
Addr
:
"
"
# 为空随机端口, 使用注册中心服务发现
...
...
service/demo/internal/conf/conf.go
View file @
80839e9e
...
...
@@ -24,8 +24,8 @@ type Config struct {
type
Server
struct
{
Name
string
Consul
Serve
r
[]
string
Etcd
Serve
r
[]
string
Consul
Add
r
[]
string
Etcd
Add
r
[]
string
Grpc
struct
{
Addr
string
}
...
...
service/demo/internal/server/grpc.go
View file @
80839e9e
...
...
@@ -14,8 +14,8 @@ import (
)
func
NewMicroServer
(
conf
*
conf
.
Config
,
svc
*
service
.
DemoService
)
micro
.
Service
{
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Serve
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Serve
r...))
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Add
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Add
r...))
opt
:=
[]
micro
.
Option
{
micro
.
Server
(
grpc
.
NewServer
()),
micro
.
Name
(
conf
.
Server
.
Name
),
...
...
service/member/config/config.yaml
View file @
80839e9e
Server
:
Name
:
"
service.member"
Consul
Serve
r
:
Consul
Add
r
:
-
192.168.233.1:8500
Grpc
:
Addr
:
"
"
# 为空随机端口, 使用注册中心服务发现
...
...
service/member/internal/conf/conf.go
View file @
80839e9e
...
...
@@ -26,8 +26,8 @@ type Config struct {
type
Server
struct
{
Name
string
Consul
Serve
r
[]
string
Etcd
Serve
r
[]
string
Consul
Add
r
[]
string
Etcd
Add
r
[]
string
Grpc
struct
{
Addr
string
}
...
...
service/member/internal/server/grpc.go
View file @
80839e9e
...
...
@@ -14,8 +14,8 @@ import (
)
func
NewMicroServer
(
conf
*
conf
.
Config
,
svc
*
service
.
MemberService
)
micro
.
Service
{
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Serve
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Serve
r...))
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Add
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Add
r...))
opt
:=
[]
micro
.
Option
{
micro
.
Server
(
grpc
.
NewServer
()),
micro
.
Name
(
conf
.
Server
.
Name
),
...
...
service/wallet/client/client.go
View file @
80839e9e
...
...
@@ -4,47 +4,29 @@ import (
"github.com/asim/go-micro/plugins/client/grpc/v4"
"github.com/asim/go-micro/plugins/registry/consul/v4"
"go-micro.dev/v4"
"go-micro.dev/v4/client"
"go-micro.dev/v4/registry"
"go-micro.dev/v4/selector"
"gomicro-base/api/member"
"gomicro-base/service/wallet/internal/conf"
)
var
(
microService
micro
.
Service
cf
*
conf
.
Config
memberSvc
member
.
MemberService
)
func
NewMicroClient
(
c
*
conf
.
Config
)
{
cf
=
c
microRegistry
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
c
.
Server
.
Consul
Serve
r
...
))
microRegistry
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
c
.
Server
.
Consul
Add
r
...
))
// 轮询访问
newSelector
:=
selector
.
NewSelector
(
selector
.
Registry
(
microRegistry
),
selector
.
SetStrategy
(
selector
.
RoundRobin
),
)
microService
=
micro
.
NewService
(
microService
:
=
micro
.
NewService
(
micro
.
Client
(
grpc
.
NewClient
()),
micro
.
Selector
(
newSelector
),
micro
.
Registry
(
microRegistry
),
micro
.
WrapClient
(
NewTimeoutWrapper
),
//micro.WrapClient(NewLogWrapper),
)
}
func
GetService
()
micro
.
Service
{
return
microService
}
func
GetClient
()
client
.
Client
{
return
microService
.
Client
()
}
func
Reconnect
()
{
NewMicroClient
(
cf
)
memberSvc
=
member
.
NewMemberService
(
conf
.
Conf
.
Client
.
Member
,
microService
.
Client
())
}
func
GetMemberSvc
()
member
.
MemberService
{
return
member
.
NewMemberService
(
conf
.
Conf
.
Client
.
Member
,
microService
.
Client
())
return
member
Svc
}
service/wallet/config/config.yaml
View file @
80839e9e
Server
:
Name
:
"
service.wallet"
Consul
Serve
r
:
Consul
Add
r
:
-
192.168.233.1:8500
Grpc
:
Addr
:
"
"
# 为空随机端口, 使用注册中心服务发现
...
...
service/wallet/internal/conf/conf.go
View file @
80839e9e
...
...
@@ -27,8 +27,8 @@ type Config struct {
type
Server
struct
{
Name
string
Consul
Serve
r
[]
string
Etcd
Serve
r
[]
string
Consul
Add
r
[]
string
Etcd
Add
r
[]
string
Grpc
struct
{
Addr
string
}
...
...
service/wallet/internal/server/grpc.go
View file @
80839e9e
...
...
@@ -14,8 +14,8 @@ import (
)
func
NewMicroServer
(
conf
*
conf
.
Config
,
svc
*
service
.
WalletService
)
micro
.
Service
{
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Serve
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Serve
r...))
reg
:=
consul
.
NewRegistry
(
registry
.
Addrs
(
conf
.
Server
.
Consul
Add
r
...
))
//reg := etcd.NewRegistry(registry.Addrs(conf.Server.Etcd
Add
r...))
opt
:=
[]
micro
.
Option
{
micro
.
Server
(
grpc
.
NewServer
()),
micro
.
Name
(
conf
.
Server
.
Name
),
...
...
tool/gateway/gateway.go
View file @
80839e9e
...
...
@@ -12,7 +12,6 @@ import (
"go-micro.dev/v4/client"
"go-micro.dev/v4/errors"
"go-micro.dev/v4/registry"
"go-micro.dev/v4/selector"
"net/http"
"os"
"sync"
...
...
@@ -74,15 +73,10 @@ func main() {
func
start
()
{
microRegistry
=
consul
.
NewRegistry
(
registry
.
Addrs
(
consulAddr
...
))
// 轮询访问
newSelector
:=
selector
.
NewSelector
(
selector
.
Registry
(
microRegistry
),
selector
.
SetStrategy
(
selector
.
RoundRobin
),
)
service
:=
micro
.
NewService
(
micro
.
Client
(
grpc
.
NewClient
()),
micro
.
Selector
(
newSelector
),
micro
.
Registry
(
microRegistry
),
micro
.
WrapClient
(
NewTimeoutWrapper
),
)
microClient
=
service
.
Client
()
...
...
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