-
Notifications
You must be signed in to change notification settings - Fork 28
/
scope.go
43 lines (38 loc) · 890 Bytes
/
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
package lintutil
import (
"fmt"
"strings"
)
const (
ScopeOperation = "operation"
ScopeSpecification = "specification"
)
var mapStringScope = map[string]string{
"operation": ScopeOperation,
"oper": ScopeOperation,
"op": ScopeOperation,
"specification": ScopeSpecification,
"spec": ScopeSpecification,
"": ScopeSpecification,
}
func ParseScope(s string) (string, error) {
s = strings.ToLower(strings.TrimSpace(s))
if scope, ok := mapStringScope[s]; ok {
return scope, nil
}
return "", fmt.Errorf("unknown scope [%s]", s)
}
func ScopeMatch(wantScope, tryScope string) bool {
wantScopeCanonical, err := ParseScope(wantScope)
if err != nil {
return false
}
tryScopeCanonical, err := ParseScope(tryScope)
if err != nil {
return false
}
if wantScopeCanonical != tryScopeCanonical {
return false
}
return true
}