forked from go-dev-frame/sponge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswag-docs.sh
36 lines (29 loc) · 981 Bytes
/
swag-docs.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
#!/bin/bash
HOST_ADDR=$1
function checkResult() {
result=$1
if [ ${result} -ne 0 ]; then
exit ${result}
fi
}
# change host addr
if [ "X${HOST_ADDR}" = "X" ];then
HOST_ADDR=$(cat cmd/serverNameExample_mixExample/main.go | grep "@host" | awk '{print $3}')
HOST_ADDR=$(echo ${HOST_ADDR} | cut -d ':' -f 1)
else
sed -i "s/@host .*:8080/@host ${HOST_ADDR}:8080/g" cmd/serverNameExample_mixExample/main.go
fi
# generate api docs
swag init -g cmd/serverNameExample_mixExample/main.go
checkResult $?
# modify duplicate numbers and error codes
sponge patch modify-dup-num --dir=internal/ecode
sponge patch modify-dup-err-code --dir=internal/ecode
colorCyan='\e[1;36m'
highBright='\e[1m'
markEnd='\e[0m'
echo ""
echo -e "${highBright}Tip:${markEnd} execute the command ${colorCyan}make run${markEnd} and then visit ${colorCyan}http://${HOST_ADDR}:8080/swagger/index.html${markEnd} in your browser."
echo ""
echo "generated api docs successfully."
echo ""