go get -u github.com/golang/protobuf/proto安装goprotobuf插件
go install github.com/golang/protobuf/protoc-gen-go@latest安装gogoprotobuf插件和依赖
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安装框架依赖
// grpc (或者git clone https://github.com/grpc/grpc-go 然后复制到google.golang.org/grpc)安装kratos toolgo get -u google.golang.org/grpc
// genproto (或者git clone https://github.com/google/go-genproto 然后复制到google.golang.org/genproto)go get google.golang.org/genproto/...
go install github.com/go-kratos/kratos/tool/kratos@latest新建示例
kratos new kratos-demo运行示例
cd kratos-demo kratos run查看http://localhost:8000/kratos-demo/start Linux:
安装
##### go install 安装:
```
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest
kratos upgrade
```
##### 源码编译安装:
```
git clone https://github.com/go-kratos/kratos
cd kratos
make install
```
### Create a service
```
# 创建项目模板
kratos new helloworld
cd helloworld
# 拉取项目依赖
go mod download
# 生成proto模板
kratos proto add api/helloworld/helloworld.proto
# 生成proto源码
kratos proto client api/helloworld/helloworld.proto
# 生成server模板
kratos proto server api/helloworld/helloworld.proto -t internal/service
# 生成所有proto源码、wire等等
go generate ./... (需要安装依赖 go install github.com/google/wire/cmd/wire@v0.5.0)
# 编译成可执行文件
go build -o ./bin/ ./...
# 运行程序
kratos run
或
./bin/demo -conf ./configs # demo为所创建项目名称
```
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)