auth
auth/grant.go
The great documentation and exported interface cleanup. Modify all our *Store interfaces to be unexported, as there's no real good reason they need to be exported, especially as they can be implemented without being exported. The interfaces shouldn't matter to 99% of users of the package, so let's not pollute our package API. Further, all methods of the interfaces are now unexported, for pretty much the same reasoning. Add a doc.go file with documentation explaining the choices the package is making and what it provides. Implement documentation on all our exported types and methods and functions, which makes golint happy. The only remaining golint warning is about NewMemstore, which will stay the way it is. The memstore type is useful outside tests for things like standing up a server quickly when we don't care about the storage, and because the type is unexported, we _need_ a New function to create an instance that can be passed to the Context.
1.1 --- a/grant.go Wed Oct 22 00:30:28 2014 -0400 1.2 +++ b/grant.go Sun Oct 26 00:53:36 2014 -0400 1.3 @@ -8,11 +8,17 @@ 1.4 ) 1.5 1.6 var ( 1.7 - ErrNoGrantStore = errors.New("no GrantStore was specified for the Context") 1.8 - ErrGrantNotFound = errors.New("grant not found in GrantStore") 1.9 - ErrGrantAlreadyExists = errors.New("grant already exists in GrantStore") 1.10 + // ErrNoGrantStore is returned when a Context tries to act on a grantStore without setting one first. 1.11 + ErrNoGrantStore = errors.New("no grantStore was specified for the Context") 1.12 + // ErrGrantNotFound is returned when a Grant is requested but not found in the grantStore. 1.13 + ErrGrantNotFound = errors.New("grant not found in grantStore") 1.14 + // ErrGrantAlreadyExists is returned when a Grant is added to a grantStore, but another Grant with the 1.15 + // same Code already exists in the grantStore. 1.16 + ErrGrantAlreadyExists = errors.New("grant already exists in grantStore") 1.17 ) 1.18 1.19 +// Grant represents an authorization grant made by a user to a Client, to 1.20 +// access user data within a defined Scope for a limited amount of time. 1.21 type Grant struct { 1.22 Code string 1.23 Created time.Time 1.24 @@ -23,13 +29,13 @@ 1.25 State string 1.26 } 1.27 1.28 -type GrantStore interface { 1.29 - GetGrant(code string) (Grant, error) 1.30 - SaveGrant(grant Grant) error 1.31 - DeleteGrant(code string) error 1.32 +type grantStore interface { 1.33 + getGrant(code string) (Grant, error) 1.34 + saveGrant(grant Grant) error 1.35 + deleteGrant(code string) error 1.36 } 1.37 1.38 -func (m *Memstore) GetGrant(code string) (Grant, error) { 1.39 +func (m *memstore) getGrant(code string) (Grant, error) { 1.40 m.grantLock.RLock() 1.41 defer m.grantLock.RUnlock() 1.42 grant, ok := m.grants[code] 1.43 @@ -39,7 +45,7 @@ 1.44 return grant, nil 1.45 } 1.46 1.47 -func (m *Memstore) SaveGrant(grant Grant) error { 1.48 +func (m *memstore) saveGrant(grant Grant) error { 1.49 m.grantLock.Lock() 1.50 defer m.grantLock.Unlock() 1.51 _, ok := m.grants[grant.Code] 1.52 @@ -50,7 +56,7 @@ 1.53 return nil 1.54 } 1.55 1.56 -func (m *Memstore) DeleteGrant(code string) error { 1.57 +func (m *memstore) deleteGrant(code string) error { 1.58 m.grantLock.Lock() 1.59 defer m.grantLock.Unlock() 1.60 _, ok := m.grants[code]