Skip to main content

Quick Start

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.

go env -w GO111MODULE=on

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

Installation

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

Project Creation

# create project's layout
kratos new helloworld

cd helloworld
# pull dependencies
go mod download
# generate proto template
kratos proto add api/helloworld/helloworld.proto
# generate proto code
kratos proto client api/helloworld/helloworld.proto
# generate server template
kratos proto server api/helloworld/helloworld.proto -t internal/service

Compilation and Running

# generate all codes of proto and wire etc.
go generate ./...

# run the application
kratos run

Try it out

curl 'http://127.0.0.1:8000/helloworld/kratos'

The response should be
{
"message": "Hello kratos"
}

Project Layout

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