wujian_develop_tool/health.go

60 lines
1.0 KiB
Go
Raw Normal View History

2022-01-05 20:25:29 +08:00
package main
import (
"bytes"
2022-01-06 22:32:03 +08:00
"git.icechen.cn/pkg/wdt/util"
2022-01-05 20:25:29 +08:00
)
type healthResp struct {
Dir bool // 应用目录健康度
Deploy bool // 部署健康度
Dockerfile bool // 构建镜像健康度
}
func (hr healthResp) IsHealth() bool {
return hr.Dir && hr.Deploy && hr.Dockerfile
}
func (hr healthResp) String() string {
if hr.IsHealth() {
return "\t\t应用情况健康"
}
b := bytes.Buffer{}
if !hr.Dir {
2022-01-06 22:32:03 +08:00
b.WriteString("\t\t应用目录:\t不存在\n")
2022-01-05 20:25:29 +08:00
}
if !hr.Deploy {
2022-01-06 22:32:03 +08:00
b.WriteString("\t\t部署文件(deploy):\t不存在\n")
2022-01-05 20:25:29 +08:00
}
if !hr.Dockerfile {
2022-01-06 22:32:03 +08:00
b.WriteString("\t\t构建文件(Dockerfile):\t不存在\n")
2022-01-05 20:25:29 +08:00
}
return b.String()
}
func healthApi(api Api) healthResp {
ret := healthResp{
Dir: false,
Deploy: false,
Dockerfile: false,
}
// Dir 健康度
2022-01-06 22:32:03 +08:00
if util.ExistDir(api.Root) {
2022-01-05 20:25:29 +08:00
ret.Dir = true
}
// Deploy 健康度
2022-01-06 22:32:03 +08:00
if util.ExistDir(api.Root + "/deploy") {
2022-01-05 20:25:29 +08:00
ret.Deploy = true
}
// Dockerfile 健康度
2022-01-06 22:32:03 +08:00
if util.ExistFile(api.Root + "/Dockerfile") {
2022-01-05 20:25:29 +08:00
ret.Dockerfile = true
}
return ret
}