Version

The version of kratos must be v2.0.0 or above.

Environment Requirements

These environments and tools must be installed properly.

The GO111MODULE should be enabled.

  1. go env -w GO111MODULE=on

If you faced with network problem (especially you are in China Mainland), please setup GOPROXY

Installation

  1. # install kratos CLI tool
  2. go get -u github.com/go-kratos/kratos/cmd/kratos/v2@latest

Project Creation

  1. # create project's layout
  2. kratos new helloworld
  3. cd helloworld
  4. # pull dependencies
  5. go mod download
  6. # generate proto template
  7. kratos proto add api/helloworld/helloworld.proto
  8. # generate proto code
  9. kratos proto client api/helloworld/helloworld.proto
  10. # generate server template
  11. kratos proto server api/helloworld/helloworld.proto -t internal/service

Compilation and Running

  1. # generate all codes of proto and wire etc.
  2. go generate ./...
  3. # run the application
  4. kratos run

Try it out

  1. curl 'http://127.0.0.1:8000/helloworld/kratos'
  2. The response should be
  3. {
  4. "message": "Hello kratos"
  5. }

Project Layout

Kratos CLI always pull the layout project from GitHub for project creation. The layout project is: