-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathadd-kitex-service.sh
executable file
·49 lines (41 loc) · 1.63 KB
/
add-kitex-service.sh
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
#!/bin/bash
# 检查 go 命令是否存在于 PATH 环境变量中
if ! command -v go &>/dev/null; then
echo "错误:go 命令未在 PATH 中找到。请安装或将其添加到 PATH 中。"
exit 1
fi
# 检查 protoc 命令是否存在于 PATH 环境变量中
if ! command -v protoc &>/dev/null; then
echo "错误:protoc 命令未在 PATH 中找到。请安装或将其添加到 PATH 中。"
# 检查操作系统是否为 macOS
if [[ $(uname) == "Darwin" ]]; then
# 如果是macOS,则检查brew是否在PATH中
if ! command -v brew &>/dev/null; then
echo "错误:brew 命令未在 PATH 中找到。请安装或将其添加到 PATH 中。"
exit 1
else
echo "尝试安装 protoc......"
brew install protobuf
fi
fi
fi
# 再次检查 protoc 命令是否存在于 PATH 环境变量中
if ! command -v protoc &>/dev/null; then
echo "错误:protoc 命令未在 PATH 中找到,看起来安装失败了。请手动安装。"
exit 1
fi
# 检查 kitex 命令是否存在于 PATH 环境变量中
if ! command -v kitex &>/dev/null; then
echo "错误:kitex 命令未在 PATH 中找到,尝试安装......"
go install github.com/cloudwego/kitex/tool/cmd/kitex@latest
fi
# 再次检查 kitex 命令是否存在于 PATH 环境变量中
if ! command -v kitex &>/dev/null; then
echo "错误:kitex 命令未在 PATH 中找到,看起来安装失败了。请手动安装。"
exit 1
fi
mkdir -p kitex_gen
kitex -module "toktik" -I idl/ idl/"$1".proto
mkdir -p service/"$1"
cd service/"$1" && kitex -module "toktik" -service "$1" -use toktik/kitex_gen/ -I ../../idl/ ../../idl/"$1".proto
go mod tidy