basic usage

hz basic usage.

Basic Usage

new: Create a new Hertz project

  1. Create a new project

    # Execute outside GOPATH, you need to specify the go mod name
    hz new -module hertz/demo
    
    # Tidy & get dependencies
    go mod tidy
    
    # Execute under GOPATH, go mod name defaults to the current path relative to GOPATH, or you can specify your own
    hz new
    
    # Tidy & get dependencies
    go mod init # `go.mod` will not be generated after the previous step executed under GOPATH.
    go mod tidy
    

    After executed, it generates a scaffold for the Hertz project in the current directory.

  2. Compiling Projects

    go build
    
  3. Run the project and test it

    Run the project:

    ./{{your binary}}
    

    Test:

    curl 127.0.0.1:8888/ping
    

    If it returns {"message":"pong"}, it works.

Notes

After creating a project with hz new, you can use the IDL file to write the project interface, and then you can use the hz update series of commands to update the project code. You can use the hz update series of commands to update the project code. For details, please refer to Using protobuf and use thrift.


Last modified September 23, 2023 : docs: update hz usage document (4134036)