From 601ef62f5d4b065e7006fab57e4d7a6e2720f1b0 Mon Sep 17 00:00:00 2001 From: kzkzzzz Date: Mon, 11 Jul 2022 18:35:31 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BF=AE=E6=94=B9readme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 81 +++++++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 8fd6153..0733e40 100644 --- a/README.md +++ b/README.md @@ -1,51 +1,48 @@ -# Kratos Project Template +### 采用单体仓库monorepo方案, 基于go-kratos构建微服务, 注册中心使用consul +#### https://github.com/go-kratos/kratos +#### https://github.com/go-kratos/beer-shop -## Install Kratos -``` -go install github.com/go-kratos/kratos/cmd/kratos/v2@latest -``` -## Create a service -``` -# Create a template project -kratos new server - -cd server -# Add a proto template -kratos proto add api/server/server.proto -# Generate the proto code -kratos proto client api/server/server.proto -# Generate the source code of service by proto file -kratos proto server api/server/server.proto -t internal/service - -go generate ./... -go build -o ./bin/ ./... -./bin/server -conf ./configs -``` -## Generate other auxiliary files by Makefile -``` -# Download and update dependencies +### 相关目录说明 +```text +api 存放对应服务的proto文件 +third_party 存放第三方的proto文件 +app/service 服务 +common 通用的工具类 +script 相关shell脚本 +tool 相关工具服务 +tool/gateway 开发调试网关, 例如: go run gateway.go -c 192.168.233.1:8500 +``` + + +#### 初始化项目, 下载依赖工具, go版本1.18以上 +```shell +# 开启go module +go env -w GO111MODULE=on +# 设置国内镜像 +go env -w GOPROXY=https://goproxy.cn,directc + +# 下载依赖 +go mod download +go mod tidy + +# 下载相关命令工具 make init -# Generate API files (include: pb.go, http, grpc, validate, swagger) by proto file -make api -# Generate all files -make all ``` -## Automated Initialization (wire) -``` -# install wire -go get github.com/google/wire/cmd/wire -# generate wire -cd cmd/server -wire +#### 新建服务, 主要是复制demo项目模板并进行替换 +```shell +# 例如创建user服务 +make service project=user ``` -## Docker -```bash -# build -docker build -t . +#### 开发环境运行服务 +```shell +# 运行demo服务, 修改代码自动热重载 +make run project=demo +``` -# run -docker run --rm -p 8000:8000 -p 9000:9000 -v :/data/conf +#### 编译 +```shell +make build project=demo ``` -- 2.22.0