-
Notifications
You must be signed in to change notification settings - Fork 53
/
Taskfile.yml
124 lines (100 loc) · 3.1 KB
/
Taskfile.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
version: "3"
#
# global vars: https://taskfile.dev/#/usage?id=variables
#
vars:
VAR1: "some-var"
# global env:
env:
ENV1: testing
DB_URL: "mysql://root:[email protected]:13306"
AccessSecret: "test_auth_secret"
AccessExpire: 3600
# env file:
#dotenv:
# - .env
################################################################################################
tasks:
run:
cmds:
- go run main.go
# ref: https://go-zero.dev/cn/docs/goctl/installation/
install:
cmds:
- GOPROXY=https://goproxy.cn/,direct go install github.com/zeromicro/go-zero/tools/goctl@latest
- goctl -v
- goctl env check -i -f --verbose
init:db:
cmds:
# - usql --help
- usql ${DB_URL} -f "proto/sql/db.sql"
- usql ${DB_URL} -f "proto/sql/schema.sql"
# 运行:
run:api:
cmds:
- |
cd api/; go run main.go -f etc/main.yaml
# 运行:
run:rpc:
cmds:
- |
cd rpc/; go run main.go -f etc/main.yaml
new:api:
cmds:
- goctl api new api
new:rpc:
cmds:
- goctl rpc new inner
# 更改proto文件, 可以方便生成业务框架代码
gen:rpc:
cmds:
# - cd hello_rpc/; goctl rpc protoc rpc.proto --go_out=./pb --go-grpc_out=./pb --zrpc_out=.
# - cd rpc/; goctl rpc protoc main.proto --go_out=. --go-grpc_out=. --zrpc_out=. --style go_zero
- goctl rpc protoc "./proto/rpc/main.proto" --go_out=./rpc --go-grpc_out=./rpc --zrpc_out=./rpc --style go_zero
# ref: https://go-zero.dev/cn/docs/design/grammar
gen:api:
cmds:
# - cd api; goctl api go --api api.api --dir . --style go_zero
- goctl api go --api "./proto/api/main.api" --dir="./api" --style go_zero
# 基于 sql, 生成 model CRUD 代码
gen:model:
cmds:
# - goctl model mysql ddl -src="./*.sql" -dir="./sql/model" -c --style go_zero
- cd proto; goctl model mysql ddl -src="./sql/*.sql" -dir="./model" -c --style go_zero
# 为 dart 客户端生成代码
gen:dart:
cmds:
- goctl api dart --api "./proto/api/main.api" --dir="./dart"
# 生成 docker 构建文件
gen:docker:
cmds:
- cd api; goctl docker -go main.go
- cd rpc; goctl docker -go main.go
ignore_error: true
# 构建 docker 镜像:
build:docker:api:
cmds:
- docker build -t api:v1 -f api/Dockerfile .
tidy:
cmds:
# - go get -u github.com/zeromicro/zero-contrib/zrpc/registry/consul
- go mod tidy -v
fmt:
cmds:
- go fmt .
# 测试 API 服务运行正常:
api:test:
cmds:
# - curl -i -X GET http://localhost:8888/eshop/v1/license/key?public_key="test1"
# - open http://localhost:8888/from/you
# - open http://localhost:8888/license/key
- |
curl --request POST \
--url http://localhost:8888/eshop/v1/license/key \
--header 'content-type: application/json' \
--data '{"product_id": "p1", "consumer_id": "c1", "shop_id": "shop1"}'
- |
curl --request GET \
--url http://localhost:8888/eshop/v1/license/key \
--header 'content-type: application/json' \
--data '{"public_key": "pk"}'