| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package dumbCounter | |
| 6 | |
| 7 import ( | |
| 8 "github.com/GoogleCloudPlatform/go-endpoints/endpoints" | |
| 9 dstore "github.com/luci/gae/service/datastore" | |
| 10 "golang.org/x/net/context" | |
| 11 ) | |
| 12 | |
| 13 // CurrentValueReq describes the inputs to the CurrentValueReq RPC. | |
| 14 type CurrentValueReq struct { | |
| 15 Name string `endpoints:"required"` | |
| 16 } | |
| 17 | |
| 18 // CurrentValueRsp describes the outputs of the CurrentValueReq RPC. | |
| 19 type CurrentValueRsp struct { | |
| 20 Val int64 `json:",string"` | |
| 21 } | |
| 22 | |
| 23 // CurrentValue gets the current value of a counter (duh) | |
| 24 func (e *Example) CurrentValue(c context.Context, r *CurrentValueReq) (rsp *Curr
entValueRsp, err error) { | |
| 25 c, err = e.Use(c, currentValueMethodInfo) | |
| 26 if err != nil { | |
| 27 return | |
| 28 } | |
| 29 | |
| 30 ds := dstore.Get(c) | |
| 31 | |
| 32 ctr := &Counter{Name: r.Name} | |
| 33 if err = ds.Get(ctr); err != nil { | |
| 34 return | |
| 35 } | |
| 36 | |
| 37 rsp = &CurrentValueRsp{ctr.Val} | |
| 38 return | |
| 39 } | |
| 40 | |
| 41 var currentValueMethodInfo = &endpoints.MethodInfo{ | |
| 42 Path: "counter/{Name}", | |
| 43 Desc: "Returns the current value held by the named counter", | |
| 44 } | |
| OLD | NEW |