-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathscope.go
57 lines (44 loc) · 1.1 KB
/
scope.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package di
// App is the name of the application scope.
const App = "app"
// Request is the name of the request scope.
const Request = "request"
// SubRequest is the name of the subrequest scope.
const SubRequest = "subrequest"
// ScopeList is a slice of scope.
type ScopeList []string
// Copy returns a copy of the ScopeList.
func (l ScopeList) Copy() ScopeList {
scopes := make(ScopeList, len(l))
copy(scopes, l)
return scopes
}
// ParentScopes returns the scopes before the one given as parameter.
func (l ScopeList) ParentScopes(scope string) ScopeList {
scopes := l.Copy()
for i, s := range scopes {
if s == scope {
return scopes[:i]
}
}
return ScopeList{}
}
// SubScopes returns the scopes after the one given as parameter.
func (l ScopeList) SubScopes(scope string) ScopeList {
scopes := l.Copy()
for i, s := range scopes {
if s == scope {
return scopes[i+1:]
}
}
return ScopeList{}
}
// Contains returns true if the ScopeList contains the given scope.
func (l ScopeList) Contains(scope string) bool {
for _, s := range l {
if scope == s {
return true
}
}
return false
}