Getting Started

cwgo is a CloudWeGo All in one code generation tool that integrates the advantages of each component to improve the developer experience.

Prepare Golang development environment

  1. If you have not set up a Golang development environment before, you can refer to Golang Installation.
  2. It is recommended to use the latest version of Golang(support version >= v1.18).
  3. Make sure to enable go mod support (when Golang >= 1.15, it is enabled by default).

After completing the environment preparation, the next step will help you get started with cwgo quickly.


go install

It’s easiest to install with the go command, or you can choose to build and install from source yourself. To see where cwgo is installed, use:

go list -f {{.Target}}

To use thrift or protobuf’s IDL to generate code, you need to install the corresponding compiler: thriftgo or protoc.

thriftgo install:

GO111MODULE=on go install

protoc install

# brew install
brew install protobuf
# Official image installation, take macos as an example
cp bin/protoc /usr/local/bin/protoc
# Make sure include/google is placed under /usr/local/include
cp -r include/google /usr/local/include/google

After the installation is successful, execute cwgo --version, thriftgo --version, protoc --version and you should be able to see the output of the specific version number (the version number is different, take x.x.x as an example):

cwgo --version

thriftgo --version

protoc --version
libprotoc x.x.x


The bottom layer of cwgo uses kitex, hz, gen tools, so the corresponding tool specifications also need to be followed, such as kitex precautions and Notes for hz.


For specific usage of cwgo, please refer to Command Line Tool.

Let’s take thrift as an example:

  1. First create a directory

    mkdir -p $GOPATH/src/local/cwgo_test
    cd $GOPATH/src/local/cwgo_test
  2. Create an idl directory

    mkdir idl
  3. Write the idl/hello.thrift file

    # idl/hello.thrift
    namespace go hello.example
    struct HelloReq {
        1: string Name (api.query="name"); // Add api annotations to facilitate parameter binding
    struct HelloResp {
        1: string RespBody;
    service HelloService {
        HelloResp HelloMethod(1: HelloReq request) (api.get="/hello");
  4. Generate project layout

    cwgo server --server_name a.b.c --type HTTP  --idl idl/hello.thrift -module {{your_module_name}}
  5. Compile and run

    go mod tidy && go mod verify
    sh && sh output/
  6. Initiate the call


Congratulations! So far you have successfully written a cwgo HTTP server and completed a call!