hz commands
hz commands.
Command line parameter description
Global
- new: Create a new Hertz project
- update: Updating an existing Hertz project
- model: Generate only model code
- client: Generate client side code based on IDL
New
- idl: Specify the idl file path (.thrift or .proto)
- service: Specify a service name to reserve for future service discovery and other functions
- module/mod: Specify the name of the go mod, which must be specified in non GOPATH scenarios. In GOPATH, the default name is the path relative to GOPATH
- out_dir: Specify the project generation path, which defaults to the current path
- handler_dir: Specify the generation path for the handler, which defaults to “biz/handler” (relative path, based on out_dir)
- model_dir: Specify the generation path for the model, which defaults to “biz/model” (relative path, based on out_dir)
- router_dir: Specify the generation path for the router, which defaults to “biz/router” (relative path, based on out_dir)
- client_dir: Specify the path for generating client-side code. If not specified, it will not be generated; Currently, a global client is generated for each service. To generate more comprehensive client-side code, please use the hz client command
- use: Specify the location of the import model package in the handler. This parameter is applicable to scenarios where model code has already been generated before generating the handler code. Use this command to directly import existing model code without generating it again
- proto_path/I: When idl is protobuf, specify the search path for idl, the same as the - I instruction for protoc
- thriftgo/t: Options for transparent transmission to thriftgo ({flag}={value})
- protoc/p: Options for transparent transmission to protoc ({flag}={value})
- option_package/P: Specify the path of the package ({include_path}={import_path})
- no_recurse: Generate only model code for the master idl, default to false
- force/f: Force the creation of a new hertz project, which will overwrite the generated files
- enable_extends: Parsing extensions in thrift idl
- json_enumstr: When idl is thrift, json enums uses string instead of num (the option passed through to thriftgo)
- unset_omitempty: When idl is protobuf, generate a model field and remove the omitempty tag; When idl is thrift, whether to add omitempty depends on whether the field is “optional” or “required”
- pb_camel_json_tag: Change the naming style of json tag to camel hump naming when generating model fields (only applicable to protobuf)
- snake_tag: tag using snake_case style naming (only valid for form, query, and json)
- rm_tag value: Remove the specified tag
- exclude_file/E: Files that do not require updates (relative to project path, supports multiple)
- customize_layout: Customize the project layout template, please refer to hz custom template use
- customize_layout_data_path value: Custom project layout template rendering parameters, please refer to hz custom template use
- customize_package: Customized project package related templates can mainly be customized for handler templates. Please refer to hz custom template use
- handler_by_method: Generate a separate handler file for each method
- protoc-plugins: Connect to third-party generated code plugins related to protoc, please refer to hz access plugin
- thrift-plugins: Connect to third-party generated code plugins related to thrift, please refer to hz access plugin
- help/h: Help Command
Update
- idl: Specify the idl file path (.thrift or .proto)
- module/mod: Specify the name of the go mod, which must be specified in non GOPATH scenarios. In GOPATH, the default name is the path relative to GOPATH
- out_dir: Specify the project generation path, which defaults to the current path
- handler_dir: Specify the generation path for the handler, which defaults to “biz/handler” (relative path, based on out_dir); Note: If updating the same set of idls, the value of handler_dir needs to be the same as when using new, otherwise redundant code will be generated and the user needs to delete it themselves.
- model_dir: Specify the generation path for the model, which defaults to “biz/model” (relative path, based on out_dir); Note: If updating the same set of idls, the value of model_dir needs to be the same as when using new, otherwise duplicate model code will be generated and inconsistent handler references will be caused.
- client_dir: Specify the path for generating client-side code. If not specified, it will not be generated; Currently, a global client is generated for each service. To generate more comprehensive client-side code, please use hz client command. Note: If updating the same set of idls, the value of client_dir needs to be the same as when using new, otherwise redundant code will be generated and the user needs to delete it themselves.
- use: Specify the location of the import model package in the handler. This parameter is applicable to scenarios where model code has already been generated before generating the handler code. Use this command to directly import existing model code without generating it again
- proto_path/I: When idl is protobuf, specify the search path for idl, the same as the - I instruction for protoc
- thriftgo/t: Options for transparent transmission to thriftgo ({flag}={value})
- protoc/p: Options for transparent transmission to protoc ({flag}={value})
- option_package/P: Specify the path of the package ({include_path}={import_path})
- no_recurse: Generate only model code for the master idl, default to false
- enable_extends: Parsing extensions in thrift idl
- json_enumstr: When idl is thrift, json enums uses string instead of num (the option passed through to thriftgo)
- unset_omitempty: When idl is protobuf, generate a model field and remove the omitempty tag; When idl is thrift, whether to add omitempty depends on whether the field is “optional” or “required”
- pb_camel_json_tag: Change the naming style of json tag to camel hump naming when generating model fields (only applicable to protobuf)
- snake_tag: tag using snake_case style naming (only valid for form, query, and json)
- rm_tag value: Remove the specified tag
- exclude_file/E: Files that do not require updates (relative to project path, supports multiple)
- customize_package: Customized project package related templates can mainly be customized for handler templates. Please refer to hz custom template use. Note: For existing handler files, a new handler function will be added according to the default template. For non existing handler files, a custom template will be used to generate the handler.
- handler_by_method: Generate a separate handler file for each method
- protoc-plugins: Connect to third-party generated code plugins related to protoc, please refer to hz access plugin
- thrift-plugins: Connect to third-party generated code plugins related to thrift, please refer to hz access plugin
- help/h: Help Command
Model
- idl: Specify the idl file path (.thrift or .proto)
- module/mod: Specify the name of the go mod, which must be specified in non GOPATH scenarios. In GOPATH, the default name is the path relative to GOPATH
- out_dir: Specify the project generation path, which defaults to the current path
- model_dir: Specify the generation path for the model, which defaults to “biz/model” (relative path, based on out_dir)
- proto_path/I: When idl is protobuf, specify the search path for idl, the same as the - I instruction for protoc
- thriftgo/t: Options for transparent transmission to thriftgo ({flag}={value})
- protoc/p: Options for transparent transmission to protoc ({flag}={value})
- no_recurse: Generate only model code for the master idl, default to false
- json_enumstr: When idl is thrift, json enums uses string instead of num (the option passed through to thriftgo)
- unset_omitempty: When idl is protobuf, generate a model field and remove the omitempty tag; When idl is thrift, whether to add omitempty depends on whether the field is “optional” or “required”
- pb_camel_json_tag: Change the naming style of json tag to camel hump naming when generating model fields (only applicable to protobuf)
- snake_tag: tag using snake_case style naming (only valid for form, query, and json)
- rm_tag value: Remove the specified tag
- exclude_file/E: Files that do not require updates (relative to project path, supports multiple)
- help/h: Help Command
Client
For examples and advanced settings of the client command, please refer to hz client code generation.
- idl: Specify the idl file path (.thrift or .proto)
- module/mod: Specify the name of the go mod, which must be specified in non GOPATH scenarios. In GOPATH, the default name is the path relative to GOPATH
- base_domain: Specify the domain to access, which can be domain name, IP: PORT, service name (in conjunction with service discovery), or declared in IDL through annotations
- model_dir: Specify the generation path for the model, which defaults to “biz/model” (relative path, based on out_dir)
- client_dir: Specify the generation path for the hertz client side code, which is generated by default at “{$MODULE}/{$MODEL_DIR}/{$namespace}/”. This parameter can be used to modify the default generation path for the code
- use: Specify the location of the import model package in the hertz client side code. This parameter is applicable to scenarios where the model code has already been generated before generating the hertz client side code. Use this command to directly import existing model code without the need to generate it again
- force_client_dir: Specify the generation path for client-side code without using service_name as a sub path. If the code defaults to generating relative paths such as “hello_service/hello_service.go” and “hello_service/hertz_client.go”, using this parameter will become “hello_service.go” and “hertz_client.go”
- proto_path/I: When idl is protobuf, specify the search path for idl, the same as the - I instruction for protoc
- thriftgo/t: Options for transparent transmission to thriftgo ({flag}={value})
- protoc/p: Options for transparent transmission to protoc ({flag}={value})
- no_recurse: Generate only model code for the master idl, default to false
- enable_extends: Parsing extensions in thrift idl
- json_enumstr: When idl is thrift, json enums uses string instead of num (the option passed through to thriftgo)
- unset_omitempty: When idl is protobuf, generate a model field and remove the omitempty tag; When idl is thrift, whether to add omitempty depends on whether the field is “optional” or “required”
- pb_camel_json_tag: Change the naming style of json tag to camel hump naming when generating model fields (only applicable to protobuf)
- snake_tag: tag using snake_case style naming (only valid for form, query, and json)
- rm_tag value: Remove the specified tag
- exclude_file/E: Files that do not require updates (relative to project path, supports multiple)
- customize_package: Customized project package related templates can mainly be customized for handler templates. Please refer to hz custom template use
- protoc-plugins: Connect to third-party generated code plugins related to protoc, please refer to hz access plugin
- thrift-plugins: Connect to third-party generated code plugins related to thrift, please refer to hz access plugin
- help/h: Help Command
Last modified
January 5, 2025
: docs: fix gzip broken link (#1181) (283a4d6)