Skip to content

Commit 99d0af8

Browse files
committed
Destroy a list of go lint errors.
1 parent ae71333 commit 99d0af8

25 files changed

Lines changed: 323 additions & 319 deletions

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ The amount of code necessary to start and configure authboss is fairly minimal,
4848
your storer, cookie storer, session storer, xsrf maker implementations.
4949

5050
```go
51-
authboss.Cfg = authboss.NewConfig()
52-
// Do all configuration here
53-
authboss.MountPath = "/authboss"
54-
authboss.LogWriter = os.Stdout
51+
// Do all configuration here (authboss.Cfg is a global
52+
// config created automatically at runtime)
53+
authboss.Cfg.MountPath = "/authboss"
54+
authboss.Cfg.LogWriter = os.Stdout
5555

5656
if err := authboss.Init(); err != nil {
5757
// Handle error, don't let program continue to run
@@ -413,4 +413,4 @@ Recover Email (txt) | recover_email.txt.tpl
413413
- [Login](https://github.com/go-authboss/authboss-sample/blob/master/ab_views/login.html.tpl)
414414
- [Recover](https://github.com/go-authboss/authboss-sample/blob/master/ab_views/recover.html.tpl)
415415
- [Recover New Password](https://github.com/go-authboss/authboss-sample/blob/master/ab_views/recover_complete.html.tpl)
416-
- [Register](https://github.com/go-authboss/authboss-sample/blob/master/ab_views/register.html.tpl)
416+
- [Register](https://github.com/go-authboss/authboss-sample/blob/master/ab_views/register.html.tpl)

auth/auth.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ func init() {
2222
authboss.RegisterModule("auth", &Auth{})
2323
}
2424

25+
// Auth module
2526
type Auth struct {
2627
templates render.Templates
2728
}
2829

30+
// Initialize module
2931
func (a *Auth) Initialize() (err error) {
3032
if authboss.Cfg.Storer == nil {
31-
return errors.New("auth: Need a Storer.")
33+
return errors.New("auth: Need a Storer")
3234
}
3335

3436
if len(authboss.Cfg.XSRFName) == 0 {
@@ -47,13 +49,15 @@ func (a *Auth) Initialize() (err error) {
4749
return nil
4850
}
4951

52+
// Routes for the module
5053
func (a *Auth) Routes() authboss.RouteTable {
5154
return authboss.RouteTable{
5255
"/login": a.loginHandlerFunc,
5356
"/logout": a.logoutHandlerFunc,
5457
}
5558
}
5659

60+
// Storage requirements
5761
func (a *Auth) Storage() authboss.StorageOptions {
5862
return authboss.StorageOptions{
5963
authboss.Cfg.PrimaryID: authboss.String,

callbacks.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ type Callbacks struct {
8282
}
8383

8484
// NewCallbacks creates a new set of before and after callbacks.
85+
// Called only by authboss internals and for testing.
8586
func NewCallbacks() *Callbacks {
8687
return &Callbacks{
8788
make(map[Event][]Before),

client_storer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "net/http"
55
const (
66
// SessionKey is the primarily used key by authboss.
77
SessionKey = "uid"
8-
// HalfAuthKey is used for sessions that have been authenticated by
8+
// SessionHalfAuthKey is used for sessions that have been authenticated by
99
// the remember module. This serves as a way to force full authentication
1010
// by denying half-authed users acccess to sensitive areas.
1111
SessionHalfAuthKey = "halfauth"

config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ type Config struct {
119119

120120
// NewConfig creates a config full of healthy default values.
121121
// Notable exceptions to default values are the Storers.
122+
// This method is called automatically on startup and is set to authboss.Cfg
123+
// so implementers need not call it. Primarily exported for testing.
122124
func NewConfig() *Config {
123125
return &Config{
124126
MountPath: "/",

confirm/confirm.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"gopkg.in/authboss.v0/internal/render"
1616
)
1717

18+
// Storer and FormValue constants
1819
const (
1920
StoreConfirmToken = "confirm_token"
2021
StoreConfirmed = "confirmed"
@@ -43,16 +44,18 @@ func init() {
4344
authboss.RegisterModule("confirm", &Confirm{})
4445
}
4546

47+
// Confirm module
4648
type Confirm struct {
4749
emailHTMLTemplates render.Templates
4850
emailTextTemplates render.Templates
4951
}
5052

53+
// Initialize the module
5154
func (c *Confirm) Initialize() (err error) {
5255
var ok bool
5356
storer, ok := authboss.Cfg.Storer.(ConfirmStorer)
5457
if storer == nil || !ok {
55-
return errors.New("confirm: Need a ConfirmStorer.")
58+
return errors.New("confirm: Need a ConfirmStorer")
5659
}
5760

5861
c.emailHTMLTemplates, err = render.LoadTemplates(authboss.Cfg.LayoutHTMLEmail, authboss.Cfg.ViewsPath, tplConfirmHTML)
@@ -64,27 +67,29 @@ func (c *Confirm) Initialize() (err error) {
6467
return err
6568
}
6669

67-
authboss.Cfg.Callbacks.Before(authboss.EventGet, c.BeforeGet)
68-
authboss.Cfg.Callbacks.Before(authboss.EventAuth, c.BeforeGet)
69-
authboss.Cfg.Callbacks.After(authboss.EventRegister, c.AfterRegister)
70+
authboss.Cfg.Callbacks.Before(authboss.EventGet, c.beforeGet)
71+
authboss.Cfg.Callbacks.Before(authboss.EventAuth, c.beforeGet)
72+
authboss.Cfg.Callbacks.After(authboss.EventRegister, c.afterRegister)
7073

7174
return nil
7275
}
7376

77+
// Routes for the module
7478
func (c *Confirm) Routes() authboss.RouteTable {
7579
return authboss.RouteTable{
7680
"/confirm": c.confirmHandler,
7781
}
7882
}
7983

84+
// Storage requirements
8085
func (c *Confirm) Storage() authboss.StorageOptions {
8186
return authboss.StorageOptions{
8287
StoreConfirmToken: authboss.String,
8388
StoreConfirmed: authboss.Bool,
8489
}
8590
}
8691

87-
func (c *Confirm) BeforeGet(ctx *authboss.Context) (authboss.Interrupt, error) {
92+
func (c *Confirm) beforeGet(ctx *authboss.Context) (authboss.Interrupt, error) {
8893
if confirmed, err := ctx.User.BoolErr(StoreConfirmed); err != nil {
8994
return authboss.InterruptNone, err
9095
} else if !confirmed {
@@ -95,7 +100,7 @@ func (c *Confirm) BeforeGet(ctx *authboss.Context) (authboss.Interrupt, error) {
95100
}
96101

97102
// AfterRegister ensures the account is not activated.
98-
func (c *Confirm) AfterRegister(ctx *authboss.Context) error {
103+
func (c *Confirm) afterRegister(ctx *authboss.Context) error {
99104
if ctx.User == nil {
100105
return errUserMissing
101106
}

confirm/confirm_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ func TestConfirm_BeforeGet(t *testing.T) {
7373
c := setup()
7474
ctx := authboss.NewContext()
7575

76-
if _, err := c.BeforeGet(ctx); err == nil {
76+
if _, err := c.beforeGet(ctx); err == nil {
7777
t.Error("Should stop the get due to attribute missing:", err)
7878
}
7979

8080
ctx.User = authboss.Attributes{
8181
StoreConfirmed: false,
8282
}
8383

84-
if interrupt, err := c.BeforeGet(ctx); interrupt != authboss.InterruptAccountNotConfirmed {
84+
if interrupt, err := c.beforeGet(ctx); interrupt != authboss.InterruptAccountNotConfirmed {
8585
t.Error("Should stop the get due to non-confirm:", interrupt)
8686
} else if err != nil {
8787
t.Error(err)
@@ -91,7 +91,7 @@ func TestConfirm_BeforeGet(t *testing.T) {
9191
StoreConfirmed: true,
9292
}
9393

94-
if interrupt, err := c.BeforeGet(ctx); interrupt != authboss.InterruptNone || err != nil {
94+
if interrupt, err := c.beforeGet(ctx); interrupt != authboss.InterruptNone || err != nil {
9595
t.Error(interrupt, err)
9696
}
9797
}
@@ -111,18 +111,18 @@ func TestConfirm_AfterRegister(t *testing.T) {
111111
sentEmail = true
112112
}
113113

114-
if err := c.AfterRegister(ctx); err != errUserMissing {
114+
if err := c.afterRegister(ctx); err != errUserMissing {
115115
t.Error("Expected it to die with user error:", err)
116116
}
117117

118118
ctx.User = authboss.Attributes{authboss.Cfg.PrimaryID: "username"}
119-
if err := c.AfterRegister(ctx); err == nil || err.(authboss.AttributeErr).Name != "email" {
119+
if err := c.afterRegister(ctx); err == nil || err.(authboss.AttributeErr).Name != "email" {
120120
t.Error("Expected it to die with e-mail address error:", err)
121121
}
122122

123123
ctx.User[authboss.StoreEmail] = "a@a.com"
124124
log.Reset()
125-
c.AfterRegister(ctx)
125+
c.afterRegister(ctx)
126126
if str := log.String(); !strings.Contains(str, "Subject: Confirm New Account") {
127127
t.Error("Expected it to send an e-mail:", str)
128128
}

context.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"time"
1010
)
1111

12+
// FormValue constants
1213
var (
1314
FormValueRedirect = "redir"
1415
FormValueOAuth2State = "state"
@@ -26,6 +27,7 @@ type Context struct {
2627
formValues map[string][]string
2728
}
2829

30+
// NewContext is exported for testing modules.
2931
func NewContext() *Context {
3032
return &Context{}
3133
}
@@ -76,7 +78,7 @@ func (c *Context) FirstPostFormValue(key string) (string, bool) {
7678
return val[0], ok
7779
}
7880

79-
// FirstFormValueErrr gets the first form value from a context created with a request
81+
// FirstFormValueErr gets the first form value from a context created with a request
8082
// and additionally returns an error not a bool if it's not found.
8183
func (c *Context) FirstFormValueErr(key string) (string, error) {
8284
val, ok := c.formValues[key]
@@ -88,7 +90,7 @@ func (c *Context) FirstFormValueErr(key string) (string, error) {
8890
return val[0], nil
8991
}
9092

91-
// FirstPostFormValue gets the first form value from a context created with a request.
93+
// FirstPostFormValueErr gets the first form value from a context created with a request.
9294
func (c *Context) FirstPostFormValueErr(key string) (string, error) {
9395
val, ok := c.postFormValues[key]
9496

errors.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ type AttributeErr struct {
1010
GotKind string
1111
}
1212

13-
func MakeAttributeErr(name string, kind DataType, val interface{}) AttributeErr {
13+
// NewAttributeErr creates a new attribute err type. Useful for when you want
14+
// to have a type mismatch error.
15+
func NewAttributeErr(name string, kind DataType, val interface{}) AttributeErr {
1416
return AttributeErr{
1517
Name: name,
1618
WantKind: kind,

errors_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
func TestAttributeErr(t *testing.T) {
99
estr := "Failed to retrieve database attribute, type was wrong: lol (want: String, got: int)"
10-
if str := MakeAttributeErr("lol", String, 5).Error(); str != estr {
10+
if str := NewAttributeErr("lol", String, 5).Error(); str != estr {
1111
t.Error("Error was wrong:", str)
1212
}
1313

0 commit comments

Comments
 (0)