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