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 "time" | |
9 | |
10 "golang.org/x/net/context" | |
11 | |
12 "github.com/luci/gae/service/info" | |
13 ) | |
14 | |
15 // InfoCounter is the counter object for the GlobalInfo service. | |
16 type InfoCounter struct { | |
17 AppID Entry | |
18 Datacenter Entry | |
19 DefaultVersionHostname Entry | |
20 InstanceID Entry | |
21 IsDevAppServer Entry | |
22 IsOverQuota Entry | |
23 IsTimeoutError Entry | |
24 ModuleHostname Entry | |
25 ModuleName Entry | |
26 RequestID Entry | |
27 ServerSoftware Entry | |
28 ServiceAccount Entry | |
29 VersionID Entry | |
30 Namespace Entry | |
31 AccessToken Entry | |
32 PublicCertificates Entry | |
33 SignBytes Entry | |
34 } | |
35 | |
36 type infoCounter struct { | |
37 c *InfoCounter | |
38 | |
39 gi info.Interface | |
40 } | |
41 | |
42 var _ info.Interface = (*infoCounter)(nil) | |
43 | |
44 func (g *infoCounter) AppID() string { | |
45 g.c.AppID.up() | |
46 return g.gi.AppID() | |
47 } | |
48 | |
49 func (g *infoCounter) Datacenter() string { | |
50 g.c.Datacenter.up() | |
51 return g.gi.Datacenter() | |
52 } | |
53 | |
54 func (g *infoCounter) DefaultVersionHostname() string { | |
55 g.c.DefaultVersionHostname.up() | |
56 return g.gi.DefaultVersionHostname() | |
57 } | |
58 | |
59 func (g *infoCounter) InstanceID() string { | |
60 g.c.InstanceID.up() | |
61 return g.gi.InstanceID() | |
62 } | |
63 | |
64 func (g *infoCounter) IsDevAppServer() bool { | |
65 g.c.IsDevAppServer.up() | |
66 return g.gi.IsDevAppServer() | |
67 } | |
68 | |
69 func (g *infoCounter) IsOverQuota(err error) bool { | |
70 g.c.IsOverQuota.up() | |
71 return g.gi.IsOverQuota(err) | |
72 } | |
73 | |
74 func (g *infoCounter) IsTimeoutError(err error) bool { | |
75 g.c.IsTimeoutError.up() | |
76 return g.gi.IsTimeoutError(err) | |
77 } | |
78 | |
79 func (g *infoCounter) ModuleHostname(module, version, instance string) (string,
error) { | |
80 ret, err := g.gi.ModuleHostname(module, version, instance) | |
81 return ret, g.c.ModuleHostname.up(err) | |
82 } | |
83 | |
84 func (g *infoCounter) ModuleName() string { | |
85 g.c.ModuleName.up() | |
86 return g.gi.ModuleName() | |
87 } | |
88 | |
89 func (g *infoCounter) RequestID() string { | |
90 g.c.RequestID.up() | |
91 return g.gi.RequestID() | |
92 } | |
93 | |
94 func (g *infoCounter) ServerSoftware() string { | |
95 g.c.ServerSoftware.up() | |
96 return g.gi.ServerSoftware() | |
97 } | |
98 | |
99 func (g *infoCounter) ServiceAccount() (string, error) { | |
100 ret, err := g.gi.ServiceAccount() | |
101 return ret, g.c.ServiceAccount.up(err) | |
102 } | |
103 | |
104 func (g *infoCounter) VersionID() string { | |
105 g.c.VersionID.up() | |
106 return g.gi.VersionID() | |
107 } | |
108 | |
109 func (g *infoCounter) Namespace(namespace string) (context.Context, error) { | |
110 ret, err := g.gi.Namespace(namespace) | |
111 return ret, g.c.Namespace.up(err) | |
112 } | |
113 | |
114 func (g *infoCounter) AccessToken(scopes ...string) (token string, expiry time.T
ime, err error) { | |
115 token, expiry, err = g.gi.AccessToken(scopes...) | |
116 g.c.AccessToken.up(err) | |
117 return | |
118 } | |
119 | |
120 func (g *infoCounter) PublicCertificates() ([]info.Certificate, error) { | |
121 ret, err := g.gi.PublicCertificates() | |
122 return ret, g.c.PublicCertificates.up(err) | |
123 } | |
124 | |
125 func (g *infoCounter) SignBytes(bytes []byte) (keyName string, signature []byte,
err error) { | |
126 keyName, signature, err = g.gi.SignBytes(bytes) | |
127 g.c.SignBytes.up(err) | |
128 return | |
129 } | |
130 | |
131 // FilterGI installs a counter GlobalInfo filter in the context. | |
132 func FilterGI(c context.Context) (context.Context, *InfoCounter) { | |
133 state := &InfoCounter{} | |
134 return info.AddFilters(c, func(ic context.Context, gi info.Interface) in
fo.Interface { | |
135 return &infoCounter{state, gi} | |
136 }), state | |
137 } | |
OLD | NEW |