Chromium Code Reviews| 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 count | |
| 6 | |
| 7 import ( | |
| 8 "github.com/luci/gae/service/user" | |
| 9 "golang.org/x/net/context" | |
| 10 ) | |
| 11 | |
| 12 // UserCounter is the counter object for the User service. | |
| 13 type UserCounter struct { | |
| 14 Counter Entry | |
| 15 CurrentOAuth Entry | |
| 16 IsAdmin Entry | |
| 17 LoginURL Entry | |
| 18 LoginURLFederated Entry | |
| 19 LogoutURL Entry | |
| 20 OAuthConsumerKey Entry | |
| 21 } | |
| 22 | |
| 23 type userCounter struct { | |
| 24 c *UserCounter | |
| 25 | |
| 26 u user.Interface | |
| 27 } | |
| 28 | |
| 29 var _ user.Interface = (*userCounter)(nil) | |
| 30 | |
| 31 func (u *userCounter) Current() *user.User { | |
| 32 u.c.Counter.up() | |
|
dnj
2015/12/15 18:59:30
Why not named "Current"?
iannucci
2015/12/15 19:12:21
Lol. Boog.
| |
| 33 return u.u.Current() | |
| 34 } | |
| 35 | |
| 36 func (u *userCounter) CurrentOAuth(scopes ...string) (*user.User, error) { | |
| 37 ret, err := u.u.CurrentOAuth(scopes...) | |
| 38 return ret, u.c.CurrentOAuth.up(err) | |
| 39 } | |
| 40 | |
| 41 func (u *userCounter) IsAdmin() bool { | |
| 42 u.c.IsAdmin.up() | |
| 43 return u.u.IsAdmin() | |
| 44 } | |
| 45 | |
| 46 func (u *userCounter) LoginURL(dest string) (string, error) { | |
| 47 ret, err := u.u.LoginURL(dest) | |
| 48 return ret, u.c.LoginURL.up(err) | |
| 49 } | |
| 50 | |
| 51 func (u *userCounter) LoginURLFederated(dest, identity string) (string, error) { | |
| 52 ret, err := u.u.LoginURLFederated(dest, identity) | |
| 53 return ret, u.c.LoginURLFederated.up(err) | |
| 54 } | |
| 55 | |
| 56 func (u *userCounter) LogoutURL(dest string) (string, error) { | |
| 57 ret, err := u.u.LogoutURL(dest) | |
| 58 return ret, u.c.LogoutURL.up(err) | |
| 59 } | |
| 60 | |
| 61 func (u *userCounter) OAuthConsumerKey() (string, error) { | |
| 62 ret, err := u.u.OAuthConsumerKey() | |
| 63 return ret, u.c.OAuthConsumerKey.up(err) | |
| 64 } | |
| 65 | |
| 66 func (u *userCounter) Testable() user.Testable { | |
| 67 return u.u.Testable() | |
| 68 } | |
| 69 | |
| 70 // FilterUser installs a counter User filter in the context. | |
| 71 func FilterUser(c context.Context) (context.Context, *UserCounter) { | |
| 72 state := &UserCounter{} | |
| 73 return user.AddFilters(c, func(ic context.Context, u user.Interface) use r.Interface { | |
| 74 return &userCounter{state, u} | |
| 75 }), state | |
| 76 } | |
| OLD | NEW |