2022-01-02 21:30:56 +04:00
|
|
|
package main
|
2021-12-24 23:28:50 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ProcessList is a map of processes' statuses.
|
|
|
|
type ProcessList map[string]bool
|
|
|
|
|
|
|
|
// ProcessXMLEntry is a XML representation of a process stored in ProcessList.
|
|
|
|
type ProcessXMLEntry struct {
|
|
|
|
XMLName xml.Name
|
|
|
|
Name string `xml:"name,attr"`
|
|
|
|
IsUp bool `xml:",chardata"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalXML implements Marshaler interface for a ProcessList.
|
2022-01-06 03:15:28 +04:00
|
|
|
func (l *ProcessList) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
|
|
|
if len(*l) == 0 {
|
2021-12-24 23:28:50 +04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := e.EncodeToken(start); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-01-06 03:15:28 +04:00
|
|
|
for key, val := range *l {
|
2021-12-24 23:28:50 +04:00
|
|
|
e.Encode(ProcessXMLEntry{
|
|
|
|
XMLName: xml.Name{Local: "Process"},
|
|
|
|
Name: key,
|
|
|
|
IsUp: val})
|
|
|
|
}
|
|
|
|
|
|
|
|
return e.EncodeToken(start.End())
|
|
|
|
}
|