/
entry.go
67 lines (54 loc) · 1.22 KB
/
entry.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
61
62
63
64
65
66
67
package util
import (
"encoding/xml"
)
// EntryType defines an entry config node used for sending and receiving XML
// from PAN-OS.
type EntryType struct {
Entries []Entry `xml:"entry"`
}
// Entry is a standalone entry struct.
type Entry struct {
XMLName xml.Name `xml:"entry"`
Value string `xml:"name,attr"`
}
// EntToStr normalizes an EntryType pointer into a list of strings.
func EntToStr(e *EntryType) []string {
if e == nil {
return nil
}
ans := make([]string, len(e.Entries))
for i := range e.Entries {
ans[i] = e.Entries[i].Value
}
return ans
}
// StrToEnt converts a list of strings into an EntryType pointer.
func StrToEnt(e []string) *EntryType {
if e == nil {
return nil
}
ans := make([]Entry, len(e))
for i := range e {
ans[i] = Entry{Value: e[i]}
}
return &EntryType{ans}
}
// EntToOneStr normalizes an EntryType pointer for a max_items=1 XML node
// into a string.
func EntToOneStr(e *EntryType) string {
if e == nil || len(e.Entries) == 0 {
return ""
}
return e.Entries[0].Value
}
// OneStrToEnt converts a string into an EntryType pointer for a max_items=1
// XML node.
func OneStrToEnt(e string) *EntryType {
if e == "" {
return nil
}
return &EntryType{[]Entry{
{Value: e},
}}
}