命令梳理

基础命令

使用 cwgo client -h 查看生成 client 代码的帮助命令。

NAME:
   cwgo client - generate RPC or HTTP client

                 Examples:
                   # Generate RPC client code 
                   cwgo client --type RPC --idl  {{path/to/IDL_file.thrift}} --service {{svc_name}}
                   
                   # Generate HTTP client code 
                   cwgo client --type HTTP --idl  {{path/to/IDL_file.thrift}} --service {{svc_name}}


USAGE:
   cwgo client [command options] [arguments...]

OPTIONS:
   --service value                                                              Specify the service name.
   --type value                                                                 Specify the generate type. (RPC or HTTP) (default: "RPC")
   --module value, --mod value                                                  Specify the Go module name to generate go.mod.
   --idl value                                                                  Specify the IDL file path. (.thrift or .proto)
   --template --template https://github.com/***/cwgo_template.git               Specify the template path. Currently cwgo supports git templates, such as --template https://github.com/***/cwgo_template.git
   --registry value                                                             Specify the registry, default is None
   --proto_search_path value, -I value [ --proto_search_path value, -I value ]  Add an IDL search path for includes. (Valid only if idl is protobuf)
   --pass value [ --pass value ]                                                pass param to hz or kitex
   --verbose                                                                    Turn on verbose mode. (default: false)
   --help, -h                                                                   show help (default: false)

详细参数

  • service:指定服务名称,用于服务注册与发现等功能
  • type:指定生成类型,支持参数 RPC、HTTP,默认为 RPC
  • module/mod:指定 go mod 名称,非 GOPATH 下必须指定,GOPATH 下默认以相对于 GOPATH 的路径作为名字
  • idl:指定主 IDL 文件路径
  • template:指定自定义模板,支持本地和 git 读取,用法详见 模板扩展
  • registry:指定服务注册组件,目前仅对 RPC 类型有用, 支持参数 ZK、NACOS、ETCD、POLARIS
  • proto_search_path/I:添加 IDL 搜索路径,只对 pb 生效
  • pass:传递给 hz 和 kitex 的参数,如传递 hzhandler_dir 参数, 则应输入 –pass “–handler_dir ./handler”。传递给工具的参数,hz 参考文档,kitex 参考文档
  • verbose:打开冗余日志模式
  • help:帮助命令