-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.go
45 lines (36 loc) · 761 Bytes
/
location.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
package cloudinfo
import (
"fmt"
"strings"
)
type Location struct {
Type string `json:"type"` // cloud, region, zone
Value string `json:"value"` // the actual value
}
type LocationArray []*Location
func makeLocation(s ...string) LocationArray {
var l LocationArray
ln := len(s)
for i := 0; i < ln; i += 2 {
l = append(l, &Location{Type: s[i], Value: s[i+1]})
}
return l
}
func (l *Location) String() string {
return fmt.Sprintf("%s=%s", l.Type, l.Value)
}
func (la LocationArray) String() string {
s := make([]string, len(la))
for n, v := range la {
s[n] = v.String()
}
return strings.Join(s, ",")
}
func (la LocationArray) Get(typ string) string {
for _, l := range la {
if l.Type == typ {
return l.Value
}
}
return ""
}