wujian_develop_tool/health.go

86 lines
1.5 KiB
Go
Raw Permalink Normal View History

2022-01-05 20:25:29 +08:00
package main
import (
"bytes"
2022-01-06 23:34:37 +08:00
"git.icechen.cn/pkg/wujian_develop_tool/config"
2022-01-06 23:04:25 +08:00
"git.icechen.cn/pkg/wujian_develop_tool/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()
}
2022-01-06 23:34:37 +08:00
func healthApi(api config.Api) healthResp {
2022-01-05 20:25:29 +08:00
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
}
2022-01-06 23:34:37 +08:00
func healthService(service config.Service) healthResp {
ret := healthResp{
Dir: false,
Deploy: false,
Dockerfile: false,
}
// Dir 健康度
if util.ExistDir(service.Root) {
ret.Dir = true
}
// Deploy 健康度
if util.ExistDir(service.Root + "/deploy") {
ret.Deploy = true
}
// Dockerfile 健康度
if util.ExistFile(service.Root + "/Dockerfile") {
ret.Dockerfile = true
}
return ret
}