github.com/gophercloud/gophercloud@v1.11.0/openstack/containerinfra/v1/quotas/results.go (about)

     1  package quotas
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"time"
     7  
     8  	"github.com/gophercloud/gophercloud"
     9  )
    10  
    11  type commonResult struct {
    12  	gophercloud.Result
    13  }
    14  
    15  // CreateResult is the response of a Create operations.
    16  type CreateResult struct {
    17  	commonResult
    18  }
    19  
    20  // Extract is a function that accepts a result and extracts a quota resource.
    21  func (r commonResult) Extract() (*Quotas, error) {
    22  	var s *Quotas
    23  	err := r.ExtractInto(&s)
    24  	return s, err
    25  }
    26  
    27  type Quotas struct {
    28  	Resource  string    `json:"resource"`
    29  	CreatedAt time.Time `json:"created_at"`
    30  	UpdatedAt time.Time `json:"updated_at"`
    31  	HardLimit int       `json:"hard_limit"`
    32  	ProjectID string    `json:"project_id"`
    33  	ID        string    `json:"-"`
    34  }
    35  
    36  func (r *Quotas) UnmarshalJSON(b []byte) error {
    37  	type tmp Quotas
    38  	var s struct {
    39  		tmp
    40  		ID interface{} `json:"id"`
    41  	}
    42  
    43  	err := json.Unmarshal(b, &s)
    44  	if err != nil {
    45  		return err
    46  	}
    47  	*r = Quotas(s.tmp)
    48  
    49  	switch t := s.ID.(type) {
    50  	case float64:
    51  		r.ID = fmt.Sprint(t)
    52  	case string:
    53  		r.ID = t
    54  	}
    55  
    56  	return nil
    57  }