forked from gophercloud/gophercloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
results.go
34 lines (28 loc) · 763 Bytes
/
results.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
package serverusage
import (
"encoding/json"
"time"
"github.com/gophercloud/gophercloud"
)
// UsageExt represents OS-SRV-USG server response fields.
type UsageExt struct {
LaunchedAt time.Time `json:"-"`
TerminatedAt time.Time `json:"-"`
}
// UnmarshalJSON helps to unmarshal UsageExt fields into needed values.
func (r *UsageExt) UnmarshalJSON(b []byte) error {
type tmp UsageExt
var s struct {
tmp
LaunchedAt gophercloud.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:launched_at"`
TerminatedAt gophercloud.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:terminated_at"`
}
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
*r = UsageExt(s.tmp)
r.LaunchedAt = time.Time(s.LaunchedAt)
r.TerminatedAt = time.Time(s.TerminatedAt)
return nil
}