OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package count | 5 package count |
6 | 6 |
7 import ( | 7 import ( |
8 "github.com/luci/gae/service/user" | 8 "github.com/luci/gae/service/user" |
9 "golang.org/x/net/context" | 9 "golang.org/x/net/context" |
10 ) | 10 ) |
11 | 11 |
12 // UserCounter is the counter object for the User service. | 12 // UserCounter is the counter object for the User service. |
13 type UserCounter struct { | 13 type UserCounter struct { |
14 Current Entry | 14 Current Entry |
15 CurrentOAuth Entry | 15 CurrentOAuth Entry |
16 IsAdmin Entry | 16 IsAdmin Entry |
17 LoginURL Entry | 17 LoginURL Entry |
18 LoginURLFederated Entry | 18 LoginURLFederated Entry |
19 LogoutURL Entry | 19 LogoutURL Entry |
20 OAuthConsumerKey Entry | 20 OAuthConsumerKey Entry |
21 } | 21 } |
22 | 22 |
23 type userCounter struct { | 23 type userCounter struct { |
24 c *UserCounter | 24 c *UserCounter |
25 | 25 |
26 » u user.Interface | 26 » u user.RawInterface |
27 } | 27 } |
28 | 28 |
29 var _ user.Interface = (*userCounter)(nil) | 29 var _ user.RawInterface = (*userCounter)(nil) |
30 | 30 |
31 func (u *userCounter) Current() *user.User { | 31 func (u *userCounter) Current() *user.User { |
32 u.c.Current.up() | 32 u.c.Current.up() |
33 return u.u.Current() | 33 return u.u.Current() |
34 } | 34 } |
35 | 35 |
36 func (u *userCounter) CurrentOAuth(scopes ...string) (*user.User, error) { | 36 func (u *userCounter) CurrentOAuth(scopes ...string) (*user.User, error) { |
37 ret, err := u.u.CurrentOAuth(scopes...) | 37 ret, err := u.u.CurrentOAuth(scopes...) |
38 return ret, u.c.CurrentOAuth.up(err) | 38 return ret, u.c.CurrentOAuth.up(err) |
39 } | 39 } |
(...skipping 16 matching lines...) Expand all Loading... |
56 func (u *userCounter) LogoutURL(dest string) (string, error) { | 56 func (u *userCounter) LogoutURL(dest string) (string, error) { |
57 ret, err := u.u.LogoutURL(dest) | 57 ret, err := u.u.LogoutURL(dest) |
58 return ret, u.c.LogoutURL.up(err) | 58 return ret, u.c.LogoutURL.up(err) |
59 } | 59 } |
60 | 60 |
61 func (u *userCounter) OAuthConsumerKey() (string, error) { | 61 func (u *userCounter) OAuthConsumerKey() (string, error) { |
62 ret, err := u.u.OAuthConsumerKey() | 62 ret, err := u.u.OAuthConsumerKey() |
63 return ret, u.c.OAuthConsumerKey.up(err) | 63 return ret, u.c.OAuthConsumerKey.up(err) |
64 } | 64 } |
65 | 65 |
66 func (u *userCounter) Testable() user.Testable { | 66 func (u *userCounter) GetTestable() user.Testable { |
67 » return u.u.Testable() | 67 » return u.u.GetTestable() |
68 } | 68 } |
69 | 69 |
70 // FilterUser installs a counter User filter in the context. | 70 // FilterUser installs a counter User filter in the context. |
71 func FilterUser(c context.Context) (context.Context, *UserCounter) { | 71 func FilterUser(c context.Context) (context.Context, *UserCounter) { |
72 state := &UserCounter{} | 72 state := &UserCounter{} |
73 » return user.AddFilters(c, func(ic context.Context, u user.Interface) use
r.Interface { | 73 » return user.AddFilters(c, func(ic context.Context, u user.RawInterface)
user.RawInterface { |
74 return &userCounter{state, u} | 74 return &userCounter{state, u} |
75 }), state | 75 }), state |
76 } | 76 } |
OLD | NEW |