scopes

Paddy 2015-12-05 Parent:b2ab1ab8f157 Child:a64a25ae2db1

1:b93938562a17 Go to Latest

scopes/scope.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.

History
1 package scopes
3 import (
4 "errors"
5 "fmt"
7 "code.secondbit.org/scopes.hg/types"
9 "golang.org/x/net/context"
10 )
12 var (
13 ErrNoStorer = errors.New("Storer not set in Context")
14 ErrScopeNotFound = errors.New("Scope not found")
15 )
17 type ErrScopeAlreadyExists string
19 func (e ErrScopeAlreadyExists) Error() string {
20 return fmt.Sprintf("scope %s already exists", string(e))
21 }
23 func stringsToScopes(s []string) scopeTypes.Scopes {
24 res := make(scopeTypes.Scopes, len(s))
25 for pos, scope := range s {
26 res[pos] = scopeTypes.Scope{ID: scope}
27 }
28 return res
29 }
31 type Storer interface {
32 CreateScopes(scopes []scopeTypes.Scope, ctx context.Context) error
33 GetScopes(ids []string, ctx context.Context) (map[string]scopeTypes.Scope, error)
34 UpdateScope(change scopeTypes.ScopeChange, ctx context.Context) error
35 RemoveScopes(ids []string, ctx context.Context) error
36 ListScopes(ctx context.Context) ([]scopeTypes.Scope, error)
37 }