File tree Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Expand file tree Collapse file tree 2 files changed +53
-2
lines changed Original file line number Diff line number Diff line change 1
- package client
1
+ package main
2
+
3
+ import (
4
+ "context"
5
+ "fmt"
6
+ "time"
7
+
8
+ "github.com/hashicorp/consul/api"
9
+
10
+ v1 "github.com/CoderI421/gframework/api/user/v1"
11
+ "github.com/CoderI421/gframework/gmicro/registry/consul"
12
+ "github.com/CoderI421/gframework/gmicro/server/rpcserver"
13
+ )
14
+
15
+ func main () {
16
+ conf := api .DefaultConfig ()
17
+ conf .Address = "127.0.0.1:8500"
18
+ conf .Scheme = "http"
19
+
20
+ client , err := api .NewClient (conf )
21
+ if err != nil {
22
+ panic (err )
23
+ }
24
+
25
+ // 服务注册
26
+ r := consul .New (client , consul .WithHealthCheck (true ))
27
+
28
+ conn , err := rpcserver .DialInsecure (
29
+ context .Background (), rpcserver .WithDiscovery (r ),
30
+ /*
31
+ 第3个/是为了第二个参数是空的
32
+ 默认格式:direct://<authority>/127.0.0.1:8078
33
+ 以后使用nacos或者其他的中心 也不用改discovery 只修改conf就可以
34
+ 服务发现可以直接去kartors里面copy registry下的etcd nacos等使用
35
+ */
36
+ rpcserver .WithEndpoint ("discovery:///user-srv" ),
37
+ rpcserver .WithClientTimeout (50 * time .Second ),
38
+ )
39
+ //conn, err := grpc.Dial("127.0.0.1:8078", grpc.WithTransportCredentials(insecure.NewCredentials()))
40
+ if err != nil {
41
+ panic (err )
42
+ }
43
+ defer conn .Close ()
44
+ uc := v1 .NewUserClient (conn )
45
+ re , err := uc .GetUserList (context .Background (), & v1.PageInfo {})
46
+ if err != nil {
47
+ panic (err )
48
+ }
49
+ fmt .Println (re )
50
+ }
Original file line number Diff line number Diff line change 9
9
)
10
10
11
11
func DTOToResponse (userdto srvv1.UserDTO ) upbv1.UserInfoResponse {
12
- return upbv1.UserInfoResponse {}
12
+ return upbv1.UserInfoResponse {
13
+ NickName : userdto .Name ,
14
+ }
13
15
}
14
16
15
17
/*
You can’t perform that action at this time.
0 commit comments