Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 1002 Bytes

README.md

File metadata and controls

58 lines (45 loc) · 1002 Bytes

goctl-rest-client

  • api文件描述
syntax = "v1"

info(
    title: "type title here"
    desc: "type desc here"
    author: "type author here"
    email: "type email here"
    version: "type version here"
)

type (
    Response {
        Code uint32 `json:"code"`
        Msg string `json:"msg"`
    }
    HelloRequest {
        Msg string `json:"msg"`
    }
)

@server(
    group: exa
    timeout: 30s
)
service demo_api {
    @doc "xx"
    @handler Hello
    post /api/v1/app/demo/hello (HelloRequest) returns (Response)
}
  • 生成基础框架
goctl api go -api exa.api -dir . --style go_zero
  • 为api生成调用客户端(插件形式)
goctl api plugin -p goctl-rest-client="rest-client --package=client --destination=http://exa_api" -api exa.api -dir .
  • 调用(通过服务名称调用)
resp, err = client.MustClient(l.svcCtx.Config.HelloDiscoverConf).Hello(l.ctx, &client.HelloRequest{
Msg: "hello,rest",
})

调用api像rpc一样简单