86 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			1.5 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package main
 | |
| 
 | |
| import (
 | |
| 	"bytes"
 | |
| 	"git.icechen.cn/pkg/wujian_develop_tool/config"
 | |
| 	"git.icechen.cn/pkg/wujian_develop_tool/util"
 | |
| )
 | |
| 
 | |
| 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不存在\n")
 | |
| 	}
 | |
| 	if !hr.Deploy {
 | |
| 		b.WriteString("\t\t部署文件(deploy):\t不存在\n")
 | |
| 	}
 | |
| 	if !hr.Dockerfile {
 | |
| 		b.WriteString("\t\t构建文件(Dockerfile):\t不存在\n")
 | |
| 	}
 | |
| 	return b.String()
 | |
| }
 | |
| 
 | |
| func healthApi(api config.Api) healthResp {
 | |
| 	ret := healthResp{
 | |
| 		Dir:        false,
 | |
| 		Deploy:     false,
 | |
| 		Dockerfile: false,
 | |
| 	}
 | |
| 
 | |
| 	// Dir 健康度
 | |
| 	if util.ExistDir(api.Root) {
 | |
| 		ret.Dir = true
 | |
| 	}
 | |
| 
 | |
| 	// Deploy 健康度
 | |
| 	if util.ExistDir(api.Root + "/deploy") {
 | |
| 		ret.Deploy = true
 | |
| 	}
 | |
| 
 | |
| 	// Dockerfile 健康度
 | |
| 	if util.ExistFile(api.Root + "/Dockerfile") {
 | |
| 		ret.Dockerfile = true
 | |
| 	}
 | |
| 
 | |
| 	return ret
 | |
| }
 | |
| 
 | |
| 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
 | |
| }
 |