-
Notifications
You must be signed in to change notification settings - Fork 108
/
feature_flags.go
89 lines (74 loc) · 2.47 KB
/
feature_flags.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
78
79
80
81
82
83
84
85
86
87
88
89
package rabbithole
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// FeatureFlag represents a feature flag.
// Feature flags are a mechanism that controls what features are considered to be enabled or available on all cluster nodes.
// If a FeatureFlag is enabled so is its associated feature (or behavior).
// If not then all nodes in the cluster will disable the feature (behavior).
type FeatureFlag struct {
Name string `json:"name"`
// Desc is the description of the feature flag.
Desc string `json:"desc,omitempty"`
// DocURL is the URL to a webpage to learn more about the feature flag.
DocURL string `json:"doc_url,omitempty"`
State State `json:"state,omitempty"`
Stability Stability `json:"stability,omitempty"`
// ProvidedBy is the RabbitMQ component or plugin which provides the feature flag.
ProvidedBy string `json:"provided_by,omitempty"`
}
// State is an enumeration for supported feature flag states
type State string
const (
// StateEnabled means that the flag is enabled
StateEnabled State = "enabled"
// StateDisabled means that the flag is disabled
StateDisabled State = "disabled"
// StateUnsupported means that one or more nodes in the cluster do not support this feature flag
// (and therefore it cannot be enabled)
StateUnsupported State = "unsupported"
)
// Stability status of a feature flag
type Stability string
const (
// StabilityStable means a feature flag enables a fully supported feature
StabilityStable Stability = "stable"
// StabilityExperimental means a feature flag enables an experimental feature
StabilityExperimental Stability = "experimental"
)
//
// GET /api/feature-flags
//
// ListFeatureFlags lists all feature flags.
func (c *Client) ListFeatureFlags() (rec []FeatureFlag, err error) {
req, err := newGETRequest(c, "feature-flags")
if err != nil {
return nil, err
}
if err = executeAndParseRequest(c, req, &rec); err != nil {
return nil, err
}
return rec, nil
}
//
// PUT /api/feature-flags/{name}/enable
//
// EnableFeatureFlag enables a feature flag.
func (c *Client) EnableFeatureFlag(featureFlagName string) (res *http.Response, err error) {
body, err := json.Marshal(FeatureFlag{Name: featureFlagName})
if err != nil {
return nil, err
}
path := fmt.Sprintf("feature-flags/%s/enable", url.PathEscape(featureFlagName))
req, err := newRequestWithBody(c, "PUT", path, body)
if err != nil {
return nil, err
}
if res, err = executeRequest(c, req); err != nil {
return nil, err
}
return res, nil
}