github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/compute/v2/extensions/serverusage/results.go (about)

     1  package serverusage
     2  
     3  import (
     4  	"encoding/json"
     5  	"time"
     6  
     7  	"github.com/huaweicloud/golangsdk"
     8  )
     9  
    10  // UsageExt represents OS-SRV-USG server response fields.
    11  type UsageExt struct {
    12  	LaunchedAt   time.Time `json:"-"`
    13  	TerminatedAt time.Time `json:"-"`
    14  }
    15  
    16  // UnmarshalJSON helps to unmarshal UsageExt fields into needed values.
    17  func (r *UsageExt) UnmarshalJSON(b []byte) error {
    18  	type tmp UsageExt
    19  	var s struct {
    20  		tmp
    21  		LaunchedAt   golangsdk.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:launched_at"`
    22  		TerminatedAt golangsdk.JSONRFC3339MilliNoZ `json:"OS-SRV-USG:terminated_at"`
    23  	}
    24  	err := json.Unmarshal(b, &s)
    25  	if err != nil {
    26  		return err
    27  	}
    28  	*r = UsageExt(s.tmp)
    29  
    30  	r.LaunchedAt = time.Time(s.LaunchedAt)
    31  	r.TerminatedAt = time.Time(s.TerminatedAt)
    32  
    33  	return nil
    34  }