Skip to content

Commit e6e2dbe

Browse files
committed
Merge pull request #164 from philips/go-code-style
Go code style
2 parents 1b0144b + 6db1880 commit e6e2dbe

16 files changed

+197
-197
lines changed

main.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func main() {
6666
flagSet.String("redeem-url", "", "Token redemption endpoint")
6767
flagSet.String("profile-url", "", "Profile access endpoint")
6868
flagSet.String("validate-url", "", "Access token validation endpoint")
69-
flagSet.String("scope", "", "Oauth scope specification")
70-
flagSet.String("approval-prompt", "force", "Oauth approval_prompt")
69+
flagSet.String("scope", "", "OAuth scope specification")
70+
flagSet.String("approval-prompt", "force", "OAuth approval_prompt")
7171

7272
flagSet.Parse(os.Args[1:])
7373

@@ -95,7 +95,7 @@ func main() {
9595
}
9696

9797
validator := NewValidator(opts.EmailDomains, opts.AuthenticatedEmailsFile)
98-
oauthproxy := NewOauthProxy(opts, validator)
98+
oauthproxy := NewOAuthProxy(opts, validator)
9999

100100
if len(opts.EmailDomains) != 0 && opts.AuthenticatedEmailsFile == "" {
101101
if len(opts.EmailDomains) > 1 {

oauthproxy.go

+43-43
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/bitly/oauth2_proxy/providers"
1919
)
2020

21-
type OauthProxy struct {
21+
type OAuthProxy struct {
2222
CookieSeed string
2323
CookieName string
2424
CookieDomain string
@@ -31,10 +31,10 @@ type OauthProxy struct {
3131
RobotsPath string
3232
PingPath string
3333
SignInPath string
34-
OauthStartPath string
35-
OauthCallbackPath string
34+
OAuthStartPath string
35+
OAuthCallbackPath string
3636

37-
redirectUrl *url.URL // the url to receive requests at
37+
redirectURL *url.URL // the url to receive requests at
3838
provider providers.Provider
3939
ProxyPrefix string
4040
SignInMessage string
@@ -86,9 +86,9 @@ func NewFileServer(path string, filesystemPath string) (proxy http.Handler) {
8686
return http.StripPrefix(path, http.FileServer(http.Dir(filesystemPath)))
8787
}
8888

89-
func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
89+
func NewOAuthProxy(opts *Options, validator func(string) bool) *OAuthProxy {
9090
serveMux := http.NewServeMux()
91-
for _, u := range opts.proxyUrls {
91+
for _, u := range opts.proxyURLs {
9292
path := u.Path
9393
switch u.Scheme {
9494
case "http", "https":
@@ -116,10 +116,10 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
116116
log.Printf("compiled skip-auth-regex => %q", u)
117117
}
118118

119-
redirectUrl := opts.redirectUrl
120-
redirectUrl.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
119+
redirectURL := opts.redirectURL
120+
redirectURL.Path = fmt.Sprintf("%s/callback", opts.ProxyPrefix)
121121

122-
log.Printf("OauthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
122+
log.Printf("OAuthProxy configured for %s Client ID: %s", opts.provider.Data().ProviderName, opts.ClientID)
123123
domain := opts.CookieDomain
124124
if domain == "" {
125125
domain = "<default>"
@@ -141,7 +141,7 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
141141
}
142142
}
143143

144-
return &OauthProxy{
144+
return &OAuthProxy{
145145
CookieName: opts.CookieName,
146146
CookieSeed: opts.CookieSecret,
147147
CookieDomain: opts.CookieDomain,
@@ -154,13 +154,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
154154
RobotsPath: "/robots.txt",
155155
PingPath: "/ping",
156156
SignInPath: fmt.Sprintf("%s/sign_in", opts.ProxyPrefix),
157-
OauthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
158-
OauthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
157+
OAuthStartPath: fmt.Sprintf("%s/start", opts.ProxyPrefix),
158+
OAuthCallbackPath: fmt.Sprintf("%s/callback", opts.ProxyPrefix),
159159

160160
ProxyPrefix: opts.ProxyPrefix,
161161
provider: opts.provider,
162162
serveMux: serveMux,
163-
redirectUrl: redirectUrl,
163+
redirectURL: redirectURL,
164164
skipAuthRegex: opts.SkipAuthRegex,
165165
compiledRegex: opts.CompiledRegex,
166166
PassBasicAuth: opts.PassBasicAuth,
@@ -171,13 +171,13 @@ func NewOauthProxy(opts *Options, validator func(string) bool) *OauthProxy {
171171
}
172172
}
173173

174-
func (p *OauthProxy) GetRedirectURI(host string) string {
174+
func (p *OAuthProxy) GetRedirectURI(host string) string {
175175
// default to the request Host if not set
176-
if p.redirectUrl.Host != "" {
177-
return p.redirectUrl.String()
176+
if p.redirectURL.Host != "" {
177+
return p.redirectURL.String()
178178
}
179179
var u url.URL
180-
u = *p.redirectUrl
180+
u = *p.redirectURL
181181
if u.Scheme == "" {
182182
if p.CookieSecure {
183183
u.Scheme = "https"
@@ -189,16 +189,16 @@ func (p *OauthProxy) GetRedirectURI(host string) string {
189189
return u.String()
190190
}
191191

192-
func (p *OauthProxy) displayCustomLoginForm() bool {
192+
func (p *OAuthProxy) displayCustomLoginForm() bool {
193193
return p.HtpasswdFile != nil && p.DisplayHtpasswdForm
194194
}
195195

196-
func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
196+
func (p *OAuthProxy) redeemCode(host, code string) (s *providers.SessionState, err error) {
197197
if code == "" {
198198
return nil, errors.New("missing code")
199199
}
200-
redirectUri := p.GetRedirectURI(host)
201-
s, err = p.provider.Redeem(redirectUri, code)
200+
redirectURI := p.GetRedirectURI(host)
201+
s, err = p.provider.Redeem(redirectURI, code)
202202
if err != nil {
203203
return
204204
}
@@ -209,7 +209,7 @@ func (p *OauthProxy) redeemCode(host, code string) (s *providers.SessionState, e
209209
return
210210
}
211211

212-
func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
212+
func (p *OAuthProxy) MakeCookie(req *http.Request, value string, expiration time.Duration, now time.Time) *http.Cookie {
213213
domain := req.Host
214214
if h, _, err := net.SplitHostPort(domain); err == nil {
215215
domain = h
@@ -235,15 +235,15 @@ func (p *OauthProxy) MakeCookie(req *http.Request, value string, expiration time
235235
}
236236
}
237237

238-
func (p *OauthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
238+
func (p *OAuthProxy) ClearCookie(rw http.ResponseWriter, req *http.Request) {
239239
http.SetCookie(rw, p.MakeCookie(req, "", time.Hour*-1, time.Now()))
240240
}
241241

242-
func (p *OauthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
242+
func (p *OAuthProxy) SetCookie(rw http.ResponseWriter, req *http.Request, val string) {
243243
http.SetCookie(rw, p.MakeCookie(req, val, p.CookieExpire, time.Now()))
244244
}
245245

246-
func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
246+
func (p *OAuthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionState, time.Duration, error) {
247247
var age time.Duration
248248
c, err := req.Cookie(p.CookieName)
249249
if err != nil {
@@ -264,7 +264,7 @@ func (p *OauthProxy) LoadCookiedSession(req *http.Request) (*providers.SessionSt
264264
return session, age, nil
265265
}
266266

267-
func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
267+
func (p *OAuthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *providers.SessionState) error {
268268
value, err := p.provider.CookieForSession(s, p.CookieCipher)
269269
if err != nil {
270270
return err
@@ -273,17 +273,17 @@ func (p *OauthProxy) SaveSession(rw http.ResponseWriter, req *http.Request, s *p
273273
return nil
274274
}
275275

276-
func (p *OauthProxy) RobotsTxt(rw http.ResponseWriter) {
276+
func (p *OAuthProxy) RobotsTxt(rw http.ResponseWriter) {
277277
rw.WriteHeader(http.StatusOK)
278278
fmt.Fprintf(rw, "User-agent: *\nDisallow: /")
279279
}
280280

281-
func (p *OauthProxy) PingPage(rw http.ResponseWriter) {
281+
func (p *OAuthProxy) PingPage(rw http.ResponseWriter) {
282282
rw.WriteHeader(http.StatusOK)
283283
fmt.Fprintf(rw, "OK")
284284
}
285285

286-
func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
286+
func (p *OAuthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, message string) {
287287
log.Printf("ErrorPage %d %s %s", code, title, message)
288288
rw.WriteHeader(code)
289289
t := struct {
@@ -298,7 +298,7 @@ func (p *OauthProxy) ErrorPage(rw http.ResponseWriter, code int, title string, m
298298
p.templates.ExecuteTemplate(rw, "error.html", t)
299299
}
300300

301-
func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
301+
func (p *OAuthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code int) {
302302
p.ClearCookie(rw, req)
303303
rw.WriteHeader(code)
304304

@@ -325,7 +325,7 @@ func (p *OauthProxy) SignInPage(rw http.ResponseWriter, req *http.Request, code
325325
p.templates.ExecuteTemplate(rw, "sign_in.html", t)
326326
}
327327

328-
func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
328+
func (p *OAuthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (string, bool) {
329329
if req.Method != "POST" || p.HtpasswdFile == nil {
330330
return "", false
331331
}
@@ -342,7 +342,7 @@ func (p *OauthProxy) ManualSignIn(rw http.ResponseWriter, req *http.Request) (st
342342
return "", false
343343
}
344344

345-
func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
345+
func (p *OAuthProxy) GetRedirect(req *http.Request) (string, error) {
346346
err := req.ParseForm()
347347

348348
if err != nil {
@@ -358,7 +358,7 @@ func (p *OauthProxy) GetRedirect(req *http.Request) (string, error) {
358358
return redirect, err
359359
}
360360

361-
func (p *OauthProxy) IsWhitelistedPath(path string) (ok bool) {
361+
func (p *OAuthProxy) IsWhitelistedPath(path string) (ok bool) {
362362
for _, u := range p.compiledRegex {
363363
ok = u.MatchString(path)
364364
if ok {
@@ -376,7 +376,7 @@ func getRemoteAddr(req *http.Request) (s string) {
376376
return
377377
}
378378

379-
func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
379+
func (p *OAuthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
380380
switch path := req.URL.Path; {
381381
case path == p.RobotsPath:
382382
p.RobotsTxt(rw)
@@ -386,16 +386,16 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
386386
p.serveMux.ServeHTTP(rw, req)
387387
case path == p.SignInPath:
388388
p.SignIn(rw, req)
389-
case path == p.OauthStartPath:
390-
p.OauthStart(rw, req)
391-
case path == p.OauthCallbackPath:
392-
p.OauthCallback(rw, req)
389+
case path == p.OAuthStartPath:
390+
p.OAuthStart(rw, req)
391+
case path == p.OAuthCallbackPath:
392+
p.OAuthCallback(rw, req)
393393
default:
394394
p.Proxy(rw, req)
395395
}
396396
}
397397

398-
func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
398+
func (p *OAuthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
399399
redirect, err := p.GetRedirect(req)
400400
if err != nil {
401401
p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -412,7 +412,7 @@ func (p *OauthProxy) SignIn(rw http.ResponseWriter, req *http.Request) {
412412
}
413413
}
414414

415-
func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
415+
func (p *OAuthProxy) OAuthStart(rw http.ResponseWriter, req *http.Request) {
416416
redirect, err := p.GetRedirect(req)
417417
if err != nil {
418418
p.ErrorPage(rw, 500, "Internal Error", err.Error())
@@ -422,7 +422,7 @@ func (p *OauthProxy) OauthStart(rw http.ResponseWriter, req *http.Request) {
422422
http.Redirect(rw, req, p.provider.GetLoginURL(redirectURI, redirect), 302)
423423
}
424424

425-
func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
425+
func (p *OAuthProxy) OAuthCallback(rw http.ResponseWriter, req *http.Request) {
426426
remoteAddr := getRemoteAddr(req)
427427

428428
// finish the oauth cycle
@@ -465,7 +465,7 @@ func (p *OauthProxy) OauthCallback(rw http.ResponseWriter, req *http.Request) {
465465
}
466466
}
467467

468-
func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
468+
func (p *OAuthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
469469
var saveSession, clearSession, revalidated bool
470470
remoteAddr := getRemoteAddr(req)
471471

@@ -555,7 +555,7 @@ func (p *OauthProxy) Proxy(rw http.ResponseWriter, req *http.Request) {
555555
p.serveMux.ServeHTTP(rw, req)
556556
}
557557

558-
func (p *OauthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
558+
func (p *OAuthProxy) CheckBasicAuth(req *http.Request) (*providers.SessionState, error) {
559559
if p.HtpasswdFile == nil {
560560
return nil, nil
561561
}

0 commit comments

Comments
 (0)