Skip to content

Commit

Permalink
fix v0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
mengdj committed Jul 1, 2023
1 parent 76941b5 commit 6446d72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion examples/test/etc/test_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ HelloDiscoverConf:
InsecureSkipVerify: true
TLS: false
Hosts:
- "192.168.10.30:7000"
#- "192.168.10.30:7000"
- "192.168.10.30:7001"
Resolver: endpoint
Transfer:
Expand Down
12 changes: 12 additions & 0 deletions examples/test/internal/logic/hello/hello_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package hello

import (
"context"
"github.com/mengdj/goctl-rest-client/examples/exa1/client"
"github.com/mengdj/goctl-rest-client/examples/exa1/client/exa"
"github.com/mengdj/goctl-rest-client/examples/test/internal/svc"
"github.com/mengdj/goctl-rest-client/examples/test/internal/types"

Expand All @@ -12,16 +14,26 @@ type HelloLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
exac exa.Client
}

func NewHelloLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HelloLogic {
return &HelloLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
exac: exa.MustClient(svcCtx.Config.HelloDiscoverConf),
}
}

func (l *HelloLogic) Hello(req *types.HelloRequest) (*types.Response, error) {
resp, err := l.exac.Hello(l.ctx, &client.HelloRequest{
Msg: "hello",
})
if nil != err {
logx.Error("请求错误", err)
} else {
logx.Info(resp)
}
return nil, nil
}
8 changes: 5 additions & 3 deletions factory/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package factory

import (
"context"
"fmt"
"github.com/google/uuid"
"github.com/mengdj/goctl-rest-client/conf"
"github.com/mengdj/goctl-rest-client/factory/rest"
Expand Down Expand Up @@ -111,6 +112,7 @@ func (f *restDiscoverClient) Invoke(ctx context.Context, method string, path str
host = ""
err error
urls strings.Builder
tar string
)
if host, err = f.subscriber.GetHost(); nil == err {
urls.WriteString(f.subscriber.Scheme())
Expand All @@ -123,15 +125,15 @@ func (f *restDiscoverClient) Invoke(ctx context.Context, method string, path str
urls.WriteString(f.contextPath)
urls.WriteString(path)
}
//execute
tar = urls.String()
if _, err = f.service.Do(
ctx,
method,
urls.String(),
tar,
data,
result,
); nil != err {
return err
return fmt.Errorf("%s(%s)", tar, err.Error())
}
return nil
}

0 comments on commit 6446d72

Please sign in to comment.