File: results.go

package info (click to toggle)
golang-github-gophercloud-utils 0.0~git20231010.80377ec-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 816 kB
  • sloc: sh: 20; makefile: 7
file content (37 lines) | stat: -rw-r--r-- 993 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
35
36
37
package gnocchi

import (
	"bytes"
	"encoding/json"
	"time"
)

// RFC3339NanoTimezone describes a common timestamp format used by Gnocchi API responses.
const RFC3339NanoTimezone = "2006-01-02T15:04:05.999999+00:00"

// RFC3339NanoNoTimezone describes a common timestamp format that can be used for Gnocchi requests
// with time ranges.
const RFC3339NanoNoTimezone = "2006-01-02T15:04:05.999999"

// JSONRFC3339NanoTimezone is a type for Gnocchi responses timestamps with a timezone offset.
type JSONRFC3339NanoTimezone time.Time

// UnmarshalJSON helps to unmarshal timestamps from Gnocchi responses to the
// JSONRFC3339NanoTimezone type.
func (jt *JSONRFC3339NanoTimezone) UnmarshalJSON(data []byte) error {
	b := bytes.NewBuffer(data)
	dec := json.NewDecoder(b)
	var s string
	if err := dec.Decode(&s); err != nil {
		return err
	}
	if s == "" {
		return nil
	}
	t, err := time.Parse(RFC3339NanoTimezone, s)
	if err != nil {
		return err
	}
	*jt = JSONRFC3339NanoTimezone(t)
	return nil
}