wujian_develop_tool/health.go

63 lines
1.1 KiB
Go

package main
import (
"bytes"
"os"
)
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 {
b.WriteString("\t\t应用目录:\t不存在")
}
if !hr.Deploy {
b.WriteString("\t\t部署文件:\t不存在")
}
if !hr.Dockerfile {
b.WriteString("\t\t构建文件:\t不存在")
}
return b.String()
}
func healthApi(api Api) healthResp {
ret := healthResp{
Dir: false,
Deploy: false,
Dockerfile: false,
}
// Dir 健康度
info, err := os.Stat(api.Root)
if err == nil && info.IsDir() {
ret.Dir = true
}
// Deploy 健康度
info, err = os.Stat(api.Root + "/deploy")
if err == nil && info.IsDir() {
ret.Deploy = true
}
// Dockerfile 健康度
info, err = os.Stat(api.Root + "/Dockerfile")
if err == nil && !info.IsDir() {
ret.Dockerfile = true
}
return ret
}