-
Notifications
You must be signed in to change notification settings - Fork 0
/
services.go
77 lines (57 loc) · 1.17 KB
/
services.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package client
import (
"fmt"
"strings"
)
// Service is an enumeration type for available services
type Service int
const (
ServiceCatalogs Service = iota + 1
ServiceEnvironments
ServiceClusters
ServiceUsers
ServiceSecurity
ServiceConfig
ServicePolicies
)
// Name returns the service name
func (s Service) Name() string {
switch s {
case ServiceCatalogs:
return "catalog"
case ServiceEnvironments:
return "environments"
case ServiceClusters:
return "cluster"
case ServiceUsers:
return "users"
case ServiceSecurity:
return "security"
case ServiceConfig:
return "config"
case ServicePolicies:
return "policies"
default:
return ""
}
}
// ParseService converts a string to a service
func ParseService(s string) (Service, error) {
switch strings.ToLower(s) {
case "catalog":
return ServiceCatalogs, nil
case "environments":
return ServiceEnvironments, nil
case "cluster":
return ServiceClusters, nil
case "users":
return ServiceUsers, nil
case "security":
return ServiceSecurity, nil
case "config":
return ServiceConfig, nil
case "policies":
return ServicePolicies, nil
}
return -1, fmt.Errorf("invalid service %s", s)
}