go检测状态 template

type systemStatus struct {
Name string
Status string
}

type InitSystemStatus struct {
Error string
ServiceList []systemStatus
}


func (n *InitSystemChecker) Output(status *InitSystemStatus) error {
tpl, isOk, err := template.TryParse(`
Systemd Service Status
Logger: journalctl -xeu SERVICE-NAME
Error: {{ .Error }}
{{ if .ServiceList -}}
Init System List:
{{- range .ServiceList }}
Name: {{.Name}} Status: {{.Status}}
{{- end }}
{{ end }}`)
if err != nil || !isOk {
if err != nil {
logger.Error("failed to render system service checkers template. error: %s", err.Error())
return err
}
return errors.New("convert system service template failed")
}
if err = tpl.Execute(os.Stdout, status); err != nil {
return err
}
return nil
}
posted @ 2023-05-23 21:37  技术颜良  阅读(13)  评论(0编辑  收藏  举报