hz 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.

Note

hz new is only used to initialize the project, use hz update to update the project. See using protobuf and use thrift.


Last modified November 11, 2024 : chore: update project descriptions (#1166) (1716eba)