forked from abneptis/GoAWS
/
attribute.go
70 lines (59 loc) · 1.26 KB
/
attribute.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
68
69
70
package sdb
import (
"http"
"strconv"
)
type Item struct {
Name string
Attribute []Attribute
}
type Attribute struct {
Name string
Value string
Exists *bool
Replace *bool
}
type AttributeList []Attribute
type AttrListType string
const (
ATTRIBUTE_LIST AttrListType = "Attribute."
EXPECTED_LIST AttrListType = "Expected."
)
func (self AttributeList) Values(afix AttrListType) (v http.Values) {
v = http.Values{}
for i := range self {
prefix := string(afix) + strconv.Itoa(i+1) + "."
v.Set(prefix+"Name", self[i].Name)
if self[i].Value != "" {
v.Set(prefix+"Value", self[i].Value)
}
if self[i].Replace != nil {
if *self[i].Replace {
v.Set(prefix+"Replace", "true")
} else {
v.Set(prefix+"Replace", "false")
}
}
if self[i].Exists != nil {
if *self[i].Exists {
v.Set(prefix+"Exists", "true")
} else {
v.Set(prefix+"Exists", "false")
}
}
}
return
}
// miscelanious helper functions.
func AttrMissing(name string) Attribute {
f := false
return Attribute{Name: name, Exists: &f}
}
func AttrExists(name string) Attribute {
t := true
return Attribute{Name: name, Exists: &t}
}
func AttrEquals(name string, value string) Attribute {
t := true
return Attribute{Name: name, Value: value, Exists: &t}
}