github.com/gophercloud/gophercloud@v1.11.0/openstack/loadbalancer/v2/quotas/results.go (about) 1 package quotas 2 3 import ( 4 "encoding/json" 5 6 "github.com/gophercloud/gophercloud" 7 ) 8 9 type commonResult struct { 10 gophercloud.Result 11 } 12 13 // Extract is a function that accepts a result and extracts a Quota resource. 14 func (r commonResult) Extract() (*Quota, error) { 15 var s struct { 16 Quota *Quota `json:"quota"` 17 } 18 err := r.ExtractInto(&s) 19 return s.Quota, err 20 } 21 22 // GetResult represents the result of a get operation. Call its Extract 23 // method to interpret it as a Quota. 24 type GetResult struct { 25 commonResult 26 } 27 28 // UpdateResult represents the result of an update operation. Call its Extract 29 // method to interpret it as a Quota. 30 type UpdateResult struct { 31 commonResult 32 } 33 34 // Quota contains load balancer quotas for a project. 35 type Quota struct { 36 // Loadbalancer represents the number of load balancers. A "-1" value means no limit. 37 Loadbalancer int `json:"-"` 38 39 // Listener represents the number of listeners. A "-1" value means no limit. 40 Listener int `json:"listener"` 41 42 // Member represents the number of members. A "-1" value means no limit. 43 Member int `json:"member"` 44 45 // Poool represents the number of pools. A "-1" value means no limit. 46 Pool int `json:"pool"` 47 48 // HealthMonitor represents the number of healthmonitors. A "-1" value means no limit. 49 Healthmonitor int `json:"-"` 50 51 // L7Policy represents the number of l7policies. A "-1" value means no limit. 52 L7Policy int `json:"l7policy"` 53 54 // L7Rule represents the number of l7rules. A "-1" value means no limit. 55 L7Rule int `json:"l7rule"` 56 } 57 58 // UnmarshalJSON provides backwards compatibility to OpenStack APIs which still 59 // return the deprecated `load_balancer` or `health_monitor` as quota values 60 // instead of `loadbalancer` and `healthmonitor`. 61 func (r *Quota) UnmarshalJSON(b []byte) error { 62 type tmp Quota 63 64 // Support both underscore and non-underscore naming. 65 var s struct { 66 tmp 67 LoadBalancer *int `json:"load_balancer"` 68 Loadbalancer *int `json:"loadbalancer"` 69 70 HealthMonitor *int `json:"health_monitor"` 71 Healthmonitor *int `json:"healthmonitor"` 72 } 73 74 err := json.Unmarshal(b, &s) 75 if err != nil { 76 return err 77 } 78 79 *r = Quota(s.tmp) 80 81 if s.LoadBalancer != nil { 82 r.Loadbalancer = *s.LoadBalancer 83 } 84 85 if s.Loadbalancer != nil { 86 r.Loadbalancer = *s.Loadbalancer 87 } 88 89 if s.HealthMonitor != nil { 90 r.Healthmonitor = *s.HealthMonitor 91 } 92 93 if s.Healthmonitor != nil { 94 r.Healthmonitor = *s.Healthmonitor 95 } 96 97 return nil 98 }