Go microservice framework kratos installation and use

windows:

  • Proxy and mod settings

    • set GO111MODULE=on
    • set GOPROXY=https://goproxy.cn/
  • Install the protobuf library file

    go get -u github.com/golang/protobuf/proto
  • Install the goprotobuf plugin

    go install github.com/golang/protobuf/protoc-gen-go@latest
  • Install the gogoprotobuf plugin and dependencies

    go install github.com/gogo/protobuf/protoc-gen-gogo@latest
    
    go install github.com/gogo/protobuf/protoc-gen-gofast@latest
    //依赖
    go get github.com/gogo/protobuf/proto
    go get github.com/gogo/protobuf/gogoproto

  • Install framework dependencies

    // grpc (or git clone https://github.com/grpc/grpc-go and copy to google.golang.org/grpc)
     go get -u google.golang.org/grpc
    
    
    // genproto (or git clone https://github.com/google/go- genproto and copy to google.golang.org/genproto)
    go get google.golang.org/genproto/...

  • Install kratos-tools

    go install github.com/go-kratos/kratos/tool/kratos@latest
  • New example

    kratos new kratos-demo

  • Run the example

    cd kratos-demo 
    kratos run

  • View http://localhost:8000/kratos-demo/start

Linux:

Install

##### go install to install:

```

go install github.com/go-kratos/kratos/cmd/kratos/v2@latest

kratos upgrade

```

##### Source code compilation and installation:

```

git clone https://github.com/go-kratos/kratos

cd kratos

make install

```

### Create a service

```

# create project template

kratos new helloworld

cd helloworld

# Pull project dependencies

go mod download

# Generate proto template

kratos proto add api/helloworld/helloworld.proto

# Generate proto source code

kratos proto client api/helloworld/helloworld.proto

# Generate server template

kratos proto server api/helloworld/helloworld.proto -t internal/service

# Generate all proto source code, wire, etc.

go generate ./... (requires go install github.com/google/wire/cmd/[email protected])

# Compile into an executable file

build -o ./bin/ ./.

# run the program

kratos run

or

./bin/demo -conf ./configs # demo is the name of the created project

```

Guess you like

Origin blog.csdn.net/MasterD56/article/details/123814764