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 » "infra/gae/libs/wrapper" | 9 » "infra/gae/libs/gae" |
10 » "infra/gae/libs/wrapper/gae" | 10 » "infra/gae/libs/gae/prod" |
11 | 11 |
12 "github.com/GoogleCloudPlatform/go-endpoints/endpoints" | 12 "github.com/GoogleCloudPlatform/go-endpoints/endpoints" |
13 ) | 13 ) |
14 | 14 |
15 // CurrentValueReq describes the inputs to the CurrentValueReq RPC. | 15 // CurrentValueReq describes the inputs to the CurrentValueReq RPC. |
16 type CurrentValueReq struct { | 16 type CurrentValueReq struct { |
17 Name string `endpoints:"required"` | 17 Name string `endpoints:"required"` |
18 } | 18 } |
19 | 19 |
20 // CurrentValueRsp describes the outputs of the CurrentValueReq RPC. | 20 // CurrentValueRsp describes the outputs of the CurrentValueReq RPC. |
21 type CurrentValueRsp struct { | 21 type CurrentValueRsp struct { |
22 Val int64 `json:",string"` | 22 Val int64 `json:",string"` |
23 } | 23 } |
24 | 24 |
25 // CurrentValue gets the current value of a counter (duh) | 25 // CurrentValue gets the current value of a counter (duh) |
26 func (Example) CurrentValue(c endpoints.Context, r *CurrentValueReq) (rsp *Curre
ntValueRsp, err error) { | 26 func (Example) CurrentValue(c context.Context, r *CurrentValueReq) (rsp *Current
ValueRsp, err error) { |
27 » ds := wrapper.GetDS(gae.Use(context.Background(), c)) | 27 » c = prod.Use(c) |
| 28 » rds := gae.GetRDS(c) |
28 | 29 |
29 » ctr := &Counter{ID: r.Name} | 30 » key := rds.NewKey("Counter", r.Name, 0, nil) |
30 » if err = ds.Get(ctr); err != nil { | 31 » ctr := &Counter{} |
| 32 » if err = rds.Get(key, ctr); err != nil { |
31 return | 33 return |
32 } | 34 } |
33 | 35 |
34 rsp = &CurrentValueRsp{ctr.Val} | 36 rsp = &CurrentValueRsp{ctr.Val} |
35 return | 37 return |
36 } | 38 } |
37 | 39 |
38 func init() { | 40 func init() { |
39 mi["CurrentValue"] = &endpoints.MethodInfo{ | 41 mi["CurrentValue"] = &endpoints.MethodInfo{ |
40 Path: "counter/{Name}", | 42 Path: "counter/{Name}", |
41 Desc: "Returns the current value held by the named counter", | 43 Desc: "Returns the current value held by the named counter", |
42 } | 44 } |
43 } | 45 } |
OLD | NEW |