File: results.go

package info (click to toggle)
golang-github-gophercloud-gophercloud 1.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 11,416 kB
  • sloc: sh: 99; makefile: 21
file content (34 lines) | stat: -rw-r--r-- 763 bytes parent folder | download | duplicates (3)
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
}