scopes
scopes/memstore.go
Separete out scopeTypes package. To avoid the same problem we had in the auth package (where importing the type required you to vendor all the database drivers, etc.) let's just separate out the scopeTypes package to hold the types, then everything can import that.
1.1 --- a/memstore.go Sat Dec 05 14:54:57 2015 -0800 1.2 +++ b/memstore.go Sat Dec 05 15:00:34 2015 -0800 1.3 @@ -4,15 +4,17 @@ 1.4 "sort" 1.5 "sync" 1.6 1.7 + "code.secondbit.org/scopes.hg/types" 1.8 + 1.9 "golang.org/x/net/context" 1.10 ) 1.11 1.12 type Memstore struct { 1.13 - scopes map[string]Scope 1.14 + scopes map[string]scopeTypes.Scope 1.15 lock sync.RWMutex 1.16 } 1.17 1.18 -func (m *Memstore) CreateScopes(scopes []Scope, ctx context.Context) error { 1.19 +func (m *Memstore) CreateScopes(scopes []scopeTypes.Scope, ctx context.Context) error { 1.20 m.lock.Lock() 1.21 defer m.lock.Unlock() 1.22 1.23 @@ -27,11 +29,11 @@ 1.24 return nil 1.25 } 1.26 1.27 -func (m *Memstore) GetScopes(ids []string, ctx context.Context) (map[string]Scope, error) { 1.28 +func (m *Memstore) GetScopes(ids []string, ctx context.Context) (map[string]scopeTypes.Scope, error) { 1.29 m.lock.RLock() 1.30 defer m.lock.RUnlock() 1.31 1.32 - scopes := map[string]Scope{} 1.33 + scopes := map[string]scopeTypes.Scope{} 1.34 for _, id := range ids { 1.35 scope, ok := m.scopes[id] 1.36 if !ok { 1.37 @@ -42,7 +44,7 @@ 1.38 return scopes, nil 1.39 } 1.40 1.41 -func (m *Memstore) UpdateScope(change ScopeChange, ctx context.Context) error { 1.42 +func (m *Memstore) UpdateScope(change scopeTypes.ScopeChange, ctx context.Context) error { 1.43 m.lock.Lock() 1.44 defer m.lock.Unlock() 1.45 1.46 @@ -50,7 +52,7 @@ 1.47 if !ok { 1.48 return ErrScopeNotFound 1.49 } 1.50 - scope = ApplyChange(change, scope) 1.51 + scope = scopeTypes.ApplyChange(change, scope) 1.52 m.scopes[change.ScopeID] = scope 1.53 return nil 1.54 } 1.55 @@ -65,15 +67,15 @@ 1.56 return nil 1.57 } 1.58 1.59 -func (m *Memstore) ListScopes(ctx context.Context) ([]Scope, error) { 1.60 +func (m *Memstore) ListScopes(ctx context.Context) ([]scopeTypes.Scope, error) { 1.61 m.lock.RLock() 1.62 defer m.lock.RUnlock() 1.63 1.64 - scopes := []Scope{} 1.65 + scopes := []scopeTypes.Scope{} 1.66 for _, scope := range m.scopes { 1.67 scopes = append(scopes, scope) 1.68 } 1.69 - sorted := Scopes(scopes) 1.70 + sorted := scopeTypes.Scopes(scopes) 1.71 sort.Sort(sorted) 1.72 scopes = sorted 1.73 return scopes, nil