github.com/gophercloud/gophercloud@v1.11.0/openstack/db/v1/configurations/results.go (about) 1 package configurations 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/gophercloud/gophercloud" 8 "github.com/gophercloud/gophercloud/pagination" 9 ) 10 11 // Config represents a configuration group API resource. 12 type Config struct { 13 Created time.Time `json:"-"` 14 Updated time.Time `json:"-"` 15 DatastoreName string `json:"datastore_name"` 16 DatastoreVersionID string `json:"datastore_version_id"` 17 DatastoreVersionName string `json:"datastore_version_name"` 18 Description string 19 ID string 20 Name string 21 Values map[string]interface{} 22 } 23 24 func (r *Config) UnmarshalJSON(b []byte) error { 25 type tmp Config 26 var s struct { 27 tmp 28 Created gophercloud.JSONRFC3339NoZ `json:"created"` 29 Updated gophercloud.JSONRFC3339NoZ `json:"updated"` 30 } 31 err := json.Unmarshal(b, &s) 32 if err != nil { 33 return err 34 } 35 *r = Config(s.tmp) 36 37 r.Created = time.Time(s.Created) 38 r.Updated = time.Time(s.Updated) 39 40 return nil 41 } 42 43 // ConfigPage contains a page of Config resources in a paginated collection. 44 type ConfigPage struct { 45 pagination.SinglePageBase 46 } 47 48 // IsEmpty indicates whether a ConfigPage is empty. 49 func (r ConfigPage) IsEmpty() (bool, error) { 50 if r.StatusCode == 204 { 51 return true, nil 52 } 53 54 is, err := ExtractConfigs(r) 55 return len(is) == 0, err 56 } 57 58 // ExtractConfigs will retrieve a slice of Config structs from a page. 59 func ExtractConfigs(r pagination.Page) ([]Config, error) { 60 var s struct { 61 Configs []Config `json:"configurations"` 62 } 63 err := (r.(ConfigPage)).ExtractInto(&s) 64 return s.Configs, err 65 } 66 67 type commonResult struct { 68 gophercloud.Result 69 } 70 71 // Extract will retrieve a Config resource from an operation result. 72 func (r commonResult) Extract() (*Config, error) { 73 var s struct { 74 Config *Config `json:"configuration"` 75 } 76 err := r.ExtractInto(&s) 77 return s.Config, err 78 } 79 80 // GetResult represents the result of a Get operation. 81 type GetResult struct { 82 commonResult 83 } 84 85 // CreateResult represents the result of a Create operation. 86 type CreateResult struct { 87 commonResult 88 } 89 90 // UpdateResult represents the result of an Update operation. 91 type UpdateResult struct { 92 gophercloud.ErrResult 93 } 94 95 // ReplaceResult represents the result of a Replace operation. 96 type ReplaceResult struct { 97 gophercloud.ErrResult 98 } 99 100 // DeleteResult represents the result of a Delete operation. 101 type DeleteResult struct { 102 gophercloud.ErrResult 103 } 104 105 // Param represents a configuration parameter API resource. 106 type Param struct { 107 Max float64 108 Min float64 109 Name string 110 RestartRequired bool `json:"restart_required"` 111 Type string 112 } 113 114 // ParamPage contains a page of Param resources in a paginated collection. 115 type ParamPage struct { 116 pagination.SinglePageBase 117 } 118 119 // IsEmpty indicates whether a ParamPage is empty. 120 func (r ParamPage) IsEmpty() (bool, error) { 121 if r.StatusCode == 204 { 122 return true, nil 123 } 124 125 is, err := ExtractParams(r) 126 return len(is) == 0, err 127 } 128 129 // ExtractParams will retrieve a slice of Param structs from a page. 130 func ExtractParams(r pagination.Page) ([]Param, error) { 131 var s struct { 132 Params []Param `json:"configuration-parameters"` 133 } 134 err := (r.(ParamPage)).ExtractInto(&s) 135 return s.Params, err 136 } 137 138 // ParamResult represents the result of an operation which retrieves details 139 // about a particular configuration param. 140 type ParamResult struct { 141 gophercloud.Result 142 } 143 144 // Extract will retrieve a param from an operation result. 145 func (r ParamResult) Extract() (*Param, error) { 146 var s *Param 147 err := r.ExtractInto(&s) 148 return s, err 149 }