OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package example | 5 package example |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
| 9 |
9 "infra/gae/libs/gae" | 10 "infra/gae/libs/gae" |
| 11 "infra/gae/libs/gae/helper" |
10 "infra/gae/libs/gae/prod" | 12 "infra/gae/libs/gae/prod" |
11 | 13 |
12 "github.com/GoogleCloudPlatform/go-endpoints/endpoints" | 14 "github.com/GoogleCloudPlatform/go-endpoints/endpoints" |
13 ) | 15 ) |
14 | 16 |
15 // ListRsp is the response from the 'List' RPC. It contains a list of Counters | 17 // ListRsp is the response from the 'List' RPC. It contains a list of Counters |
16 // including their IDs and Values. | 18 // including their IDs and Values. |
17 type ListRsp struct { | 19 type ListRsp struct { |
18 Counters []Counter | 20 Counters []Counter |
19 } | 21 } |
20 | 22 |
21 // List returns a list of all the counters. Note that it's very poorly | 23 // List returns a list of all the counters. Note that it's very poorly |
22 // implemented! It's completely unpaged. I don't care :). | 24 // implemented! It's completely unpaged. I don't care :). |
23 func (Example) List(c context.Context) (rsp *ListRsp, err error) { | 25 func (Example) List(c context.Context) (rsp *ListRsp, err error) { |
24 rds := gae.GetRDS(prod.Use(c)) | 26 rds := gae.GetRDS(prod.Use(c)) |
25 rsp = &ListRsp{} | 27 rsp = &ListRsp{} |
26 » _, err = rds.GetAll(rds.NewQuery("Counter"), &rsp.Counters) | 28 » dst := []gae.DSPropertyMap{} |
| 29 » _, err = rds.GetAll(rds.NewQuery("Counter"), &dst) |
27 if err != nil { | 30 if err != nil { |
28 return | 31 return |
29 } | 32 } |
| 33 rsp.Counters = make([]Counter, len(dst)) |
| 34 for i, m := range dst { |
| 35 if err = helper.GetPLS(rsp.Counters[i]).Load(m); err != nil { |
| 36 return |
| 37 } |
| 38 } |
30 return | 39 return |
31 } | 40 } |
32 | 41 |
33 func init() { | 42 func init() { |
34 mi["List"] = &endpoints.MethodInfo{ | 43 mi["List"] = &endpoints.MethodInfo{ |
35 Path: "counter", | 44 Path: "counter", |
36 Desc: "Returns all of the available counters", | 45 Desc: "Returns all of the available counters", |
37 } | 46 } |
38 } | 47 } |
OLD | NEW |