Skip to content

Commit 725e695

Browse files
committed
Fix golint errors in auth.go
1 parent 9e8021f commit 725e695

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

auth.go

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,31 @@ import (
77
"golang.org/x/net/context"
88
)
99

10-
/*
11-
Request handlers must take AuthenticatedRequest instead of http.Request
12-
*/
10+
// AuthenticatedRequest is passed to AuthenticatedHandlerFunc instead
11+
// of *http.Request.
1312
type AuthenticatedRequest struct {
1413
http.Request
15-
/*
16-
Authenticated user name. Current API implies that Username is
17-
never empty, which means that authentication is always done
18-
before calling the request handler.
19-
*/
14+
// Username is the authenticated user name. Current API implies that
15+
// Username is never empty, which means that authentication is
16+
// always done before calling the request handler.
2017
Username string
2118
}
2219

23-
/*
24-
AuthenticatedHandlerFunc is like http.HandlerFunc, but takes
25-
AuthenticatedRequest instead of http.Request
26-
*/
20+
// AuthenticatedHandlerFunc is like http.HandlerFunc, but takes
21+
// AuthenticatedRequest instead of http.Request
2722
type AuthenticatedHandlerFunc func(http.ResponseWriter, *AuthenticatedRequest)
2823

29-
/*
30-
Authenticator wraps an AuthenticatedHandlerFunc with
31-
authentication-checking code.
32-
33-
Typical Authenticator usage is something like:
34-
35-
authenticator := SomeAuthenticator(...)
36-
http.HandleFunc("/", authenticator(my_handler))
37-
38-
Authenticator wrapper checks the user authentication and calls the
39-
wrapped function only after authentication has succeeded. Otherwise,
40-
it returns a handler which initiates the authentication procedure.
41-
*/
24+
// Authenticator wraps an AuthenticatedHandlerFunc with
25+
// authentication-checking code.
26+
//
27+
// Typical Authenticator usage is something like:
28+
//
29+
// authenticator := SomeAuthenticator(...)
30+
// http.HandleFunc("/", authenticator(my_handler))
31+
//
32+
// Authenticator wrapper checks the user authentication and calls the
33+
// wrapped function only after authentication has succeeded. Otherwise,
34+
// it returns a handler which initiates the authentication procedure.
4235
type Authenticator func(AuthenticatedHandlerFunc) http.HandlerFunc
4336

4437
// Info contains authentication information for the request.
@@ -73,8 +66,14 @@ func (i *Info) UpdateHeaders(headers http.Header) {
7366

7467
type key int // used for context keys
7568

76-
var infoKey key = 0
69+
var infoKey key
7770

71+
// AuthenticatorInterface is the interface implemented by BasicAuth
72+
// and DigestAuth authenticators.
73+
//
74+
// Deprecated: this interface is not coherent. New code should define
75+
// and use your own interfaces with a required subset of authenticator
76+
// methods.
7877
type AuthenticatorInterface interface {
7978
// NewContext returns a new context carrying authentication
8079
// information extracted from the request.
@@ -101,6 +100,9 @@ func FromContext(ctx context.Context) *Info {
101100
// successful).
102101
const AuthUsernameHeader = "X-Authenticated-Username"
103102

103+
// JustCheck returns a new http.HandlerFunc, which requires
104+
// authenticator to successfully authenticate a user before calling
105+
// wrapped http.HandlerFunc.
104106
func JustCheck(auth AuthenticatorInterface, wrapped http.HandlerFunc) http.HandlerFunc {
105107
return auth.Wrap(func(w http.ResponseWriter, ar *AuthenticatedRequest) {
106108
ar.Header.Set(AuthUsernameHeader, ar.Username)

0 commit comments

Comments
 (0)