/
object_storage.go
64 lines (52 loc) · 1.54 KB
/
object_storage.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
package upcloud
import "encoding/json"
// ObjectStorage represents a Object Storage
type ObjectStorage struct {
Created string `json:"created"`
Description string `json:"description"`
Name string `json:"name"`
Size int `json:"size"`
State string `json:"state"`
URL string `json:"url"`
UUID string `json:"uuid"`
Zone string `json:"zone"`
}
// ObjectStorages represent a /object-storage response
type ObjectStorages struct {
ObjectStorages []ObjectStorage `json:"object_storages"`
}
// UnmarshalJSON is a custom unmarshaller that deals with
// deeply embedded values.
func (o *ObjectStorages) UnmarshalJSON(b []byte) error {
type objectStorageWrapper struct {
ObjectStorages []ObjectStorage `json:"object_storage"`
}
v := struct {
ObjectStorages objectStorageWrapper `json:"object_storages"`
}{}
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
o.ObjectStorages = v.ObjectStorages.ObjectStorages
return nil
}
// ObjectStorageDetails represents details about a Object Storage
type ObjectStorageDetails struct {
ObjectStorage
UsedSpace int `json:"used_space"`
}
// UnmarshalJSON is a custom unmarshaller that deals with
// deeply embedded values.
func (o *ObjectStorageDetails) UnmarshalJSON(b []byte) error {
type localObjectStorageDetails ObjectStorageDetails
v := struct {
ObjectStorageDetails localObjectStorageDetails `json:"object_storage"`
}{}
err := json.Unmarshal(b, &v)
if err != nil {
return err
}
(*o) = ObjectStorageDetails(v.ObjectStorageDetails)
return nil
}