Skip to content

Commit 6446d72

Browse files
committed
fix v0.1.2
1 parent 76941b5 commit 6446d72

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

examples/test/etc/test_api.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ HelloDiscoverConf:
1818
InsecureSkipVerify: true
1919
TLS: false
2020
Hosts:
21-
- "192.168.10.30:7000"
21+
#- "192.168.10.30:7000"
2222
- "192.168.10.30:7001"
2323
Resolver: endpoint
2424
Transfer:

examples/test/internal/logic/hello/hello_logic.go

+12
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package hello
22

33
import (
44
"context"
5+
"github.com/mengdj/goctl-rest-client/examples/exa1/client"
6+
"github.com/mengdj/goctl-rest-client/examples/exa1/client/exa"
57
"github.com/mengdj/goctl-rest-client/examples/test/internal/svc"
68
"github.com/mengdj/goctl-rest-client/examples/test/internal/types"
79

@@ -12,16 +14,26 @@ type HelloLogic struct {
1214
logx.Logger
1315
ctx context.Context
1416
svcCtx *svc.ServiceContext
17+
exac exa.Client
1518
}
1619

1720
func NewHelloLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HelloLogic {
1821
return &HelloLogic{
1922
Logger: logx.WithContext(ctx),
2023
ctx: ctx,
2124
svcCtx: svcCtx,
25+
exac: exa.MustClient(svcCtx.Config.HelloDiscoverConf),
2226
}
2327
}
2428

2529
func (l *HelloLogic) Hello(req *types.HelloRequest) (*types.Response, error) {
30+
resp, err := l.exac.Hello(l.ctx, &client.HelloRequest{
31+
Msg: "hello",
32+
})
33+
if nil != err {
34+
logx.Error("请求错误", err)
35+
} else {
36+
logx.Info(resp)
37+
}
2638
return nil, nil
2739
}

factory/client.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package factory
88

99
import (
1010
"context"
11+
"fmt"
1112
"github.com/google/uuid"
1213
"github.com/mengdj/goctl-rest-client/conf"
1314
"github.com/mengdj/goctl-rest-client/factory/rest"
@@ -111,6 +112,7 @@ func (f *restDiscoverClient) Invoke(ctx context.Context, method string, path str
111112
host = ""
112113
err error
113114
urls strings.Builder
115+
tar string
114116
)
115117
if host, err = f.subscriber.GetHost(); nil == err {
116118
urls.WriteString(f.subscriber.Scheme())
@@ -123,15 +125,15 @@ func (f *restDiscoverClient) Invoke(ctx context.Context, method string, path str
123125
urls.WriteString(f.contextPath)
124126
urls.WriteString(path)
125127
}
126-
//execute
128+
tar = urls.String()
127129
if _, err = f.service.Do(
128130
ctx,
129131
method,
130-
urls.String(),
132+
tar,
131133
data,
132134
result,
133135
); nil != err {
134-
return err
136+
return fmt.Errorf("%s(%s)", tar, err.Error())
135137
}
136138
return nil
137139
}

0 commit comments

Comments
 (0)