type systemStatus struct {
Name string
Status string
}
type InitSystemStatus struct {
Error string
ServiceList []systemStatus
}
标签:Status,return,nil,err,检测,template,Error,go From: https://www.cnblogs.com/cheyunhua/p/17426483.html
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
}