-
Notifications
You must be signed in to change notification settings - Fork 124
/
feature_flag.go
71 lines (61 loc) · 2.09 KB
/
feature_flag.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
package client
import (
"context"
"net/url"
"github.com/cloudfoundry/go-cfclient/v3/internal/path"
"github.com/cloudfoundry/go-cfclient/v3/resource"
)
type FeatureFlagClient commonClient
// FeatureFlagListOptions list filters
type FeatureFlagListOptions struct {
*ListOptions
}
// NewFeatureFlagListOptions creates new options to pass to list
func NewFeatureFlagListOptions() *FeatureFlagListOptions {
return &FeatureFlagListOptions{
ListOptions: NewListOptions(),
}
}
func (o FeatureFlagListOptions) ToQueryString() (url.Values, error) {
return o.ListOptions.ToQueryString(o)
}
// Get the specified feature flag
func (c *FeatureFlagClient) Get(ctx context.Context, featureFlag resource.FeatureFlagType) (*resource.FeatureFlag, error) {
var ff resource.FeatureFlag
err := c.client.get(ctx, path.Format("/v3/feature_flags/%s", featureFlag), &ff)
if err != nil {
return nil, err
}
return &ff, nil
}
// List pages feature flags
func (c *FeatureFlagClient) List(ctx context.Context, opts *FeatureFlagListOptions) ([]*resource.FeatureFlag, *Pager, error) {
if opts == nil {
opts = NewFeatureFlagListOptions()
}
var res resource.FeatureFlagList
err := c.client.list(ctx, "/v3/feature_flags", opts.ToQueryString, &res)
if err != nil {
return nil, nil, err
}
pager := NewPager(res.Pagination)
return res.Resources, pager, nil
}
// ListAll retrieves all feature flags
func (c *FeatureFlagClient) ListAll(ctx context.Context, opts *FeatureFlagListOptions) ([]*resource.FeatureFlag, error) {
if opts == nil {
opts = NewFeatureFlagListOptions()
}
return AutoPage[*FeatureFlagListOptions, *resource.FeatureFlag](opts, func(opts *FeatureFlagListOptions) ([]*resource.FeatureFlag, *Pager, error) {
return c.List(ctx, opts)
})
}
// Update the specified attributes of the feature flag
func (c *FeatureFlagClient) Update(ctx context.Context, featureFlag resource.FeatureFlagType, r *resource.FeatureFlagUpdate) (*resource.FeatureFlag, error) {
var d resource.FeatureFlag
_, err := c.client.patch(ctx, path.Format("/v3/feature_flags/%s", featureFlag), r, &d)
if err != nil {
return nil, err
}
return &d, nil
}