/
cloud.go
58 lines (49 loc) · 1.1 KB
/
cloud.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
package lepton
import (
"encoding/json"
"time"
)
// CloudImage abstracts images for various cloud providers
type CloudImage struct {
ID string
Name string
Status string
Size int64
Path string
Created time.Time
Tag string // could merge w/below
Labels []string
}
// CloudInstance represents the instance that widely use in different
// Cloud Providers.
// mainly used for formatting standard response from any cloud provider
type CloudInstance struct {
ID string
Name string
Status string
Created string // TODO: prob. should be datetime w/helpers for human formatting
PrivateIps []string
PublicIps []string
Ports []string
Image string
}
// MarshalJSON ensures correct json serialization of potential null
// vals.
func (c CloudInstance) MarshalJSON() ([]byte, error) {
type Alias CloudInstance
a := struct {
Alias
}{
Alias: (Alias)(c),
}
if a.PublicIps == nil {
a.PublicIps = make([]string, 0)
}
if a.PrivateIps == nil {
a.PrivateIps = make([]string, 0)
}
if a.Ports == nil {
a.Ports = make([]string, 0)
}
return json.Marshal(a)
}