OLD | NEW |
(Empty) | |
| 1 // Package dumb_counter provides access to the . |
| 2 // |
| 3 // Usage example: |
| 4 // |
| 5 // import "google.golang.org/api/dumb_counter/v1" |
| 6 // ... |
| 7 // dumb_counterService, err := dumb_counter.New(oauthHttpClient) |
| 8 package dumb_counter |
| 9 |
| 10 import ( |
| 11 "bytes" |
| 12 "encoding/json" |
| 13 "errors" |
| 14 "fmt" |
| 15 "golang.org/x/net/context" |
| 16 "google.golang.org/api/googleapi" |
| 17 "io" |
| 18 "net/http" |
| 19 "net/url" |
| 20 "strconv" |
| 21 "strings" |
| 22 ) |
| 23 |
| 24 // Always reference these packages, just in case the auto-generated code |
| 25 // below doesn't. |
| 26 var _ = bytes.NewBuffer |
| 27 var _ = strconv.Itoa |
| 28 var _ = fmt.Sprintf |
| 29 var _ = json.NewDecoder |
| 30 var _ = io.Copy |
| 31 var _ = url.Parse |
| 32 var _ = googleapi.Version |
| 33 var _ = errors.New |
| 34 var _ = strings.Replace |
| 35 var _ = context.Background |
| 36 |
| 37 const apiId = "dumb_counter:v1" |
| 38 const apiName = "dumb_counter" |
| 39 const apiVersion = "v1" |
| 40 const basePath = "http://localhost:8080/_ah/api/dumb_counter/v1/" |
| 41 |
| 42 func New(client *http.Client) (*Service, error) { |
| 43 if client == nil { |
| 44 return nil, errors.New("client is nil") |
| 45 } |
| 46 s := &Service{client: client, BasePath: basePath} |
| 47 return s, nil |
| 48 } |
| 49 |
| 50 type Service struct { |
| 51 client *http.Client |
| 52 BasePath string // API endpoint base URL |
| 53 UserAgent string // optional additional User-Agent fragment |
| 54 } |
| 55 |
| 56 func (s *Service) userAgent() string { |
| 57 if s.UserAgent == "" { |
| 58 return googleapi.UserAgent |
| 59 } |
| 60 return googleapi.UserAgent + " " + s.UserAgent |
| 61 } |
| 62 |
| 63 type AddReq struct { |
| 64 Delta int64 `json:"Delta,omitempty,string"` |
| 65 |
| 66 Name string `json:"Name,omitempty"` |
| 67 } |
| 68 |
| 69 type AddRsp struct { |
| 70 Cur int64 `json:"Cur,omitempty,string"` |
| 71 |
| 72 Prev int64 `json:"Prev,omitempty,string"` |
| 73 } |
| 74 |
| 75 type CASReq struct { |
| 76 Name string `json:"Name,omitempty"` |
| 77 |
| 78 NewVal int64 `json:"NewVal,omitempty,string"` |
| 79 |
| 80 OldVal int64 `json:"OldVal,omitempty,string"` |
| 81 } |
| 82 |
| 83 type Counter struct { |
| 84 ID string `json:"ID,omitempty"` |
| 85 |
| 86 Val int64 `json:"Val,omitempty,string"` |
| 87 } |
| 88 |
| 89 type CurrentValueRsp struct { |
| 90 Val int64 `json:"Val,omitempty,string"` |
| 91 } |
| 92 |
| 93 type ListRsp struct { |
| 94 Counters []*Counter `json:"Counters,omitempty"` |
| 95 } |
| 96 |
| 97 // method id "dumb_counter.add": |
| 98 |
| 99 type AddCall struct { |
| 100 s *Service |
| 101 Name string |
| 102 addreq *AddReq |
| 103 opt_ map[string]interface{} |
| 104 } |
| 105 |
| 106 // Add: Add an an amount to a particular counter |
| 107 func (s *Service) Add(Name string, addreq *AddReq) *AddCall { |
| 108 c := &AddCall{s: s, opt_: make(map[string]interface{})} |
| 109 c.Name = Name |
| 110 c.addreq = addreq |
| 111 return c |
| 112 } |
| 113 |
| 114 // Fields allows partial responses to be retrieved. |
| 115 // See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse |
| 116 // for more information. |
| 117 func (c *AddCall) Fields(s ...googleapi.Field) *AddCall { |
| 118 c.opt_["fields"] = googleapi.CombineFields(s) |
| 119 return c |
| 120 } |
| 121 |
| 122 func (c *AddCall) Do() (*AddRsp, error) { |
| 123 var body io.Reader = nil |
| 124 body, err := googleapi.WithoutDataWrapper.JSONReader(c.addreq) |
| 125 if err != nil { |
| 126 return nil, err |
| 127 } |
| 128 ctype := "application/json" |
| 129 params := make(url.Values) |
| 130 params.Set("alt", "json") |
| 131 if v, ok := c.opt_["fields"]; ok { |
| 132 params.Set("fields", fmt.Sprintf("%v", v)) |
| 133 } |
| 134 urls := googleapi.ResolveRelative(c.s.BasePath, "counter/{Name}") |
| 135 urls += "?" + params.Encode() |
| 136 req, _ := http.NewRequest("POST", urls, body) |
| 137 googleapi.Expand(req.URL, map[string]string{ |
| 138 "Name": c.Name, |
| 139 }) |
| 140 req.Header.Set("Content-Type", ctype) |
| 141 req.Header.Set("User-Agent", c.s.userAgent()) |
| 142 res, err := c.s.client.Do(req) |
| 143 if err != nil { |
| 144 return nil, err |
| 145 } |
| 146 defer googleapi.CloseBody(res) |
| 147 if err := googleapi.CheckResponse(res); err != nil { |
| 148 return nil, err |
| 149 } |
| 150 var ret *AddRsp |
| 151 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { |
| 152 return nil, err |
| 153 } |
| 154 return ret, nil |
| 155 // { |
| 156 // "description": "Add an an amount to a particular counter", |
| 157 // "httpMethod": "POST", |
| 158 // "id": "dumb_counter.add", |
| 159 // "parameterOrder": [ |
| 160 // "Name" |
| 161 // ], |
| 162 // "parameters": { |
| 163 // "Name": { |
| 164 // "location": "path", |
| 165 // "required": true, |
| 166 // "type": "string" |
| 167 // } |
| 168 // }, |
| 169 // "path": "counter/{Name}", |
| 170 // "request": { |
| 171 // "$ref": "AddReq", |
| 172 // "parameterName": "resource" |
| 173 // }, |
| 174 // "response": { |
| 175 // "$ref": "AddRsp" |
| 176 // } |
| 177 // } |
| 178 |
| 179 } |
| 180 |
| 181 // method id "dumb_counter.cas": |
| 182 |
| 183 type CasCall struct { |
| 184 s *Service |
| 185 Name string |
| 186 casreq *CASReq |
| 187 opt_ map[string]interface{} |
| 188 } |
| 189 |
| 190 // Cas: Compare and swap a counter value |
| 191 func (s *Service) Cas(Name string, casreq *CASReq) *CasCall { |
| 192 c := &CasCall{s: s, opt_: make(map[string]interface{})} |
| 193 c.Name = Name |
| 194 c.casreq = casreq |
| 195 return c |
| 196 } |
| 197 |
| 198 // Fields allows partial responses to be retrieved. |
| 199 // See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse |
| 200 // for more information. |
| 201 func (c *CasCall) Fields(s ...googleapi.Field) *CasCall { |
| 202 c.opt_["fields"] = googleapi.CombineFields(s) |
| 203 return c |
| 204 } |
| 205 |
| 206 func (c *CasCall) Do() error { |
| 207 var body io.Reader = nil |
| 208 body, err := googleapi.WithoutDataWrapper.JSONReader(c.casreq) |
| 209 if err != nil { |
| 210 return err |
| 211 } |
| 212 ctype := "application/json" |
| 213 params := make(url.Values) |
| 214 params.Set("alt", "json") |
| 215 if v, ok := c.opt_["fields"]; ok { |
| 216 params.Set("fields", fmt.Sprintf("%v", v)) |
| 217 } |
| 218 urls := googleapi.ResolveRelative(c.s.BasePath, "counter/{Name}/cas") |
| 219 urls += "?" + params.Encode() |
| 220 req, _ := http.NewRequest("POST", urls, body) |
| 221 googleapi.Expand(req.URL, map[string]string{ |
| 222 "Name": c.Name, |
| 223 }) |
| 224 req.Header.Set("Content-Type", ctype) |
| 225 req.Header.Set("User-Agent", c.s.userAgent()) |
| 226 res, err := c.s.client.Do(req) |
| 227 if err != nil { |
| 228 return err |
| 229 } |
| 230 defer googleapi.CloseBody(res) |
| 231 if err := googleapi.CheckResponse(res); err != nil { |
| 232 return err |
| 233 } |
| 234 return nil |
| 235 // { |
| 236 // "description": "Compare and swap a counter value", |
| 237 // "httpMethod": "POST", |
| 238 // "id": "dumb_counter.cas", |
| 239 // "parameterOrder": [ |
| 240 // "Name" |
| 241 // ], |
| 242 // "parameters": { |
| 243 // "Name": { |
| 244 // "location": "path", |
| 245 // "required": true, |
| 246 // "type": "string" |
| 247 // } |
| 248 // }, |
| 249 // "path": "counter/{Name}/cas", |
| 250 // "request": { |
| 251 // "$ref": "CASReq", |
| 252 // "parameterName": "resource" |
| 253 // } |
| 254 // } |
| 255 |
| 256 } |
| 257 |
| 258 // method id "dumb_counter.currentvalue": |
| 259 |
| 260 type CurrentvalueCall struct { |
| 261 s *Service |
| 262 Name string |
| 263 opt_ map[string]interface{} |
| 264 } |
| 265 |
| 266 // Currentvalue: Returns the current value held by the named counter |
| 267 func (s *Service) Currentvalue(Name string) *CurrentvalueCall { |
| 268 c := &CurrentvalueCall{s: s, opt_: make(map[string]interface{})} |
| 269 c.Name = Name |
| 270 return c |
| 271 } |
| 272 |
| 273 // Fields allows partial responses to be retrieved. |
| 274 // See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse |
| 275 // for more information. |
| 276 func (c *CurrentvalueCall) Fields(s ...googleapi.Field) *CurrentvalueCall { |
| 277 c.opt_["fields"] = googleapi.CombineFields(s) |
| 278 return c |
| 279 } |
| 280 |
| 281 func (c *CurrentvalueCall) Do() (*CurrentValueRsp, error) { |
| 282 var body io.Reader = nil |
| 283 params := make(url.Values) |
| 284 params.Set("alt", "json") |
| 285 if v, ok := c.opt_["fields"]; ok { |
| 286 params.Set("fields", fmt.Sprintf("%v", v)) |
| 287 } |
| 288 urls := googleapi.ResolveRelative(c.s.BasePath, "counter/{Name}") |
| 289 urls += "?" + params.Encode() |
| 290 req, _ := http.NewRequest("GET", urls, body) |
| 291 googleapi.Expand(req.URL, map[string]string{ |
| 292 "Name": c.Name, |
| 293 }) |
| 294 req.Header.Set("User-Agent", c.s.userAgent()) |
| 295 res, err := c.s.client.Do(req) |
| 296 if err != nil { |
| 297 return nil, err |
| 298 } |
| 299 defer googleapi.CloseBody(res) |
| 300 if err := googleapi.CheckResponse(res); err != nil { |
| 301 return nil, err |
| 302 } |
| 303 var ret *CurrentValueRsp |
| 304 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { |
| 305 return nil, err |
| 306 } |
| 307 return ret, nil |
| 308 // { |
| 309 // "description": "Returns the current value held by the named counter
", |
| 310 // "httpMethod": "GET", |
| 311 // "id": "dumb_counter.currentvalue", |
| 312 // "parameterOrder": [ |
| 313 // "Name" |
| 314 // ], |
| 315 // "parameters": { |
| 316 // "Name": { |
| 317 // "location": "path", |
| 318 // "required": true, |
| 319 // "type": "string" |
| 320 // } |
| 321 // }, |
| 322 // "path": "counter/{Name}", |
| 323 // "response": { |
| 324 // "$ref": "CurrentValueRsp" |
| 325 // } |
| 326 // } |
| 327 |
| 328 } |
| 329 |
| 330 // method id "dumb_counter.list": |
| 331 |
| 332 type ListCall struct { |
| 333 s *Service |
| 334 opt_ map[string]interface{} |
| 335 } |
| 336 |
| 337 // List: Returns all of the available counters |
| 338 func (s *Service) List() *ListCall { |
| 339 c := &ListCall{s: s, opt_: make(map[string]interface{})} |
| 340 return c |
| 341 } |
| 342 |
| 343 // Fields allows partial responses to be retrieved. |
| 344 // See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse |
| 345 // for more information. |
| 346 func (c *ListCall) Fields(s ...googleapi.Field) *ListCall { |
| 347 c.opt_["fields"] = googleapi.CombineFields(s) |
| 348 return c |
| 349 } |
| 350 |
| 351 func (c *ListCall) Do() (*ListRsp, error) { |
| 352 var body io.Reader = nil |
| 353 params := make(url.Values) |
| 354 params.Set("alt", "json") |
| 355 if v, ok := c.opt_["fields"]; ok { |
| 356 params.Set("fields", fmt.Sprintf("%v", v)) |
| 357 } |
| 358 urls := googleapi.ResolveRelative(c.s.BasePath, "counter") |
| 359 urls += "?" + params.Encode() |
| 360 req, _ := http.NewRequest("GET", urls, body) |
| 361 googleapi.SetOpaque(req.URL) |
| 362 req.Header.Set("User-Agent", c.s.userAgent()) |
| 363 res, err := c.s.client.Do(req) |
| 364 if err != nil { |
| 365 return nil, err |
| 366 } |
| 367 defer googleapi.CloseBody(res) |
| 368 if err := googleapi.CheckResponse(res); err != nil { |
| 369 return nil, err |
| 370 } |
| 371 var ret *ListRsp |
| 372 if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { |
| 373 return nil, err |
| 374 } |
| 375 return ret, nil |
| 376 // { |
| 377 // "description": "Returns all of the available counters", |
| 378 // "httpMethod": "GET", |
| 379 // "id": "dumb_counter.list", |
| 380 // "path": "counter", |
| 381 // "response": { |
| 382 // "$ref": "ListRsp" |
| 383 // } |
| 384 // } |
| 385 |
| 386 } |
OLD | NEW |