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.
6 "code.secondbit.org/uuid"
10 tokens map[string]Token
11 refreshTokenLookup map[string]string
12 profileTokenLookup map[string][]string
13 tokenLock sync.RWMutex
15 grants map[string]Grant
16 grantLock sync.RWMutex
18 clients map[string]Client
19 profileClientLookup map[string][]uuid.ID
20 clientLock sync.RWMutex
22 endpoints map[string][]Endpoint
23 endpointLock sync.RWMutex
25 profiles map[string]Profile
26 profileLock sync.RWMutex
28 logins map[string]Login
29 profileLoginLookup map[string][]string
30 loginLock sync.RWMutex
33 // NewMemstore returns an in-memory version of our datastores,
34 // which is handy for tests. Though the implementation is concurrency-safe,
35 // if makes no attempt to persist the data, and therefore it is inadvisable
36 // to use it in a production setting.
37 func NewMemstore() *memstore {
39 tokens: map[string]Token{},
40 refreshTokenLookup: map[string]string{},
41 profileTokenLookup: map[string][]string{},
42 grants: map[string]Grant{},
43 clients: map[string]Client{},
44 profileClientLookup: map[string][]uuid.ID{},
45 endpoints: map[string][]Endpoint{},
46 profiles: map[string]Profile{},
47 logins: map[string]Login{},
48 profileLoginLookup: map[string][]string{},
52 func (m *memstore) lookupTokenByRefresh(token string) (string, error) {
54 defer m.tokenLock.RUnlock()
55 t, ok := m.refreshTokenLookup[token]
57 return "", ErrTokenNotFound
62 func (m *memstore) lookupTokensByProfileID(id string) ([]string, error) {
64 defer m.tokenLock.RUnlock()
65 return m.profileTokenLookup[id], nil
68 func (m *memstore) lookupClientsByProfileID(id string) []uuid.ID {
70 defer m.clientLock.RUnlock()
71 c, ok := m.profileClientLookup[id]