-
Notifications
You must be signed in to change notification settings - Fork 24
/
RebootResponse.go
60 lines (51 loc) · 1.42 KB
/
RebootResponse.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package cwmp
import (
"encoding/xml"
"fmt"
"time"
"github.com/ca17/teamsacs/common/xmlx"
)
// RebootResponse reboot response
type RebootResponse struct {
ID string
Name string
}
type rebootResponseBodyStruct struct {
Body rebootResponseStruct `xml:"cwmp:RebootResponse"`
}
type rebootResponseStruct struct {
}
// GetID get msg id
func (msg *RebootResponse) GetID() string {
if len(msg.ID) < 1 {
msg.ID = fmt.Sprintf("ID:intrnl.unset.id.%s%d.%d", msg.GetName(), time.Now().Unix(), time.Now().UnixNano())
}
return msg.ID
}
// GetName get msg type
func (msg *RebootResponse) GetName() string {
return "RebootResponse"
}
// CreateXML encode into xml
func (msg *RebootResponse) CreateXML() []byte {
env := Envelope{}
env.XmlnsEnv = "http://schemas.xmlsoap.org/soap/envelope/"
env.XmlnsEnc = "http://schemas.xmlsoap.org/soap/encoding/"
env.XmlnsXsd = "http://www.w3.org/2001/XMLSchema"
env.XmlnsXsi = "http://www.w3.org/2001/XMLSchema-instance"
env.XmlnsCwmp = "urn:dslforum-org:cwmp-1-0"
id := IDStruct{Attr: "1", Value: msg.GetID()}
env.Header = HeaderStruct{ID: id}
body := rebootResponseStruct{}
env.Body = rebootResponseBodyStruct{body}
// output, err := xml.Marshal(env)
output, err := xml.MarshalIndent(env, " ", " ")
if err != nil {
fmt.Printf("error: %v\n", err)
}
return output
}
// Parse decode from xml
func (msg *RebootResponse) Parse(doc *xmlx.Document) {
msg.ID = getDocNodeValue(doc, "*", "ID")
}