scopes

Paddy 2015-12-05 Child:a64a25ae2db1

1:b93938562a17 Go to Latest

scopes/types/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 scopeTypes
3 // Scope represents a limit on the access that a grant provides.
4 type Scope struct {
5 ID string
6 Name string
7 Description string
8 }
10 func ApplyChange(change ScopeChange, scope Scope) Scope {
11 changed := scope
12 if change.Name != nil {
13 changed.Name = *change.Name
14 }
15 if change.Description != nil {
16 changed.Description = *change.Description
17 }
18 return changed
19 }
21 type Scopes []Scope
23 func (s Scopes) Len() int {
24 return len(s)
25 }
27 func (s Scopes) Swap(i, j int) {
28 s[i], s[j] = s[j], s[i]
29 }
31 func (s Scopes) Less(i, j int) bool {
32 return s[i].ID < s[j].ID
33 }
35 func (s Scopes) Strings() []string {
36 res := make([]string, len(s))
37 for pos, scope := range s {
38 res[pos] = scope.ID
39 }
40 return res
41 }
43 // ScopeChange represents a change to a Scope.
44 type ScopeChange struct {
45 ScopeID string
46 Name *string
47 Description *string
48 }
50 func (s ScopeChange) Empty() bool {
51 return s.Name == nil && s.Description == nil
52 }