-
Notifications
You must be signed in to change notification settings - Fork 781
Expand file tree
/
Copy pathappevaluate.go
More file actions
172 lines (151 loc) · 5.92 KB
/
Copy pathappevaluate.go
File metadata and controls
172 lines (151 loc) · 5.92 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
package flagship
import (
"context"
"errors"
"fmt"
"net/http"
"net/url"
"reflect"
"slices"
"github.com/cloudflare/cloudflare-go/v7/internal/apijson"
"github.com/cloudflare/cloudflare-go/v7/internal/apiquery"
"github.com/cloudflare/cloudflare-go/v7/internal/param"
"github.com/cloudflare/cloudflare-go/v7/internal/requestconfig"
"github.com/cloudflare/cloudflare-go/v7/option"
"github.com/cloudflare/cloudflare-go/v7/shared"
"github.com/tidwall/gjson"
)
// AppEvaluateService contains methods and other services that help with
// interacting with the cloudflare API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewAppEvaluateService] method instead.
type AppEvaluateService struct {
Options []option.RequestOption
}
// NewAppEvaluateService generates a new service that applies the given options to
// each request. These options are applied after the parent client's options (if
// there is one), and before any request-specific options.
func NewAppEvaluateService(opts ...option.RequestOption) (r *AppEvaluateService) {
r = &AppEvaluateService{}
r.Options = opts
return
}
// Evaluates a flag against the provided context. Pass context attributes as query
// parameters; values are coerced to numbers or booleans where unambiguous. For
// low-latency in-Worker evaluation, prefer the Flagship binding over this
// endpoint.
func (r *AppEvaluateService) Get(ctx context.Context, appID string, params AppEvaluateGetParams, opts ...option.RequestOption) (res *AppEvaluateGetResponse, err error) {
opts = slices.Concat(r.Options, opts)
if params.AccountID.Value == "" {
err = errors.New("missing required account_id parameter")
return nil, err
}
if appID == "" {
err = errors.New("missing required app_id parameter")
return nil, err
}
path := fmt.Sprintf("accounts/%s/flagship/apps/%s/evaluate", params.AccountID, appID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, params, &res, opts...)
return res, err
}
type AppEvaluateGetResponse struct {
// Key of the evaluated flag.
FlagKey string `json:"flagKey" api:"required"`
// Reason the evaluator selected this variation.
Reason AppEvaluateGetResponseReason `json:"reason" api:"required"`
// Name of the variation that supplied the resolved value.
Variant string `json:"variant" api:"required"`
Value AppEvaluateGetResponseValueUnion `json:"value"`
JSON appEvaluateGetResponseJSON `json:"-"`
}
// appEvaluateGetResponseJSON contains the JSON metadata for the struct
// [AppEvaluateGetResponse]
type appEvaluateGetResponseJSON struct {
FlagKey apijson.Field
Reason apijson.Field
Variant apijson.Field
Value apijson.Field
raw string
ExtraFields map[string]apijson.Field
}
func (r *AppEvaluateGetResponse) UnmarshalJSON(data []byte) (err error) {
return apijson.UnmarshalRoot(data, r)
}
func (r appEvaluateGetResponseJSON) RawJSON() string {
return r.raw
}
// Reason the evaluator selected this variation.
type AppEvaluateGetResponseReason string
const (
AppEvaluateGetResponseReasonStatic AppEvaluateGetResponseReason = "STATIC"
AppEvaluateGetResponseReasonTargetingMatch AppEvaluateGetResponseReason = "TARGETING_MATCH"
AppEvaluateGetResponseReasonDefault AppEvaluateGetResponseReason = "DEFAULT"
AppEvaluateGetResponseReasonDisabled AppEvaluateGetResponseReason = "DISABLED"
AppEvaluateGetResponseReasonSplit AppEvaluateGetResponseReason = "SPLIT"
)
func (r AppEvaluateGetResponseReason) IsKnown() bool {
switch r {
case AppEvaluateGetResponseReasonStatic, AppEvaluateGetResponseReasonTargetingMatch, AppEvaluateGetResponseReasonDefault, AppEvaluateGetResponseReasonDisabled, AppEvaluateGetResponseReasonSplit:
return true
}
return false
}
// Union satisfied by [shared.UnionString], [shared.UnionFloat],
// [shared.UnionBool], [AppEvaluateGetResponseValueMap] or
// [AppEvaluateGetResponseValueArray].
type AppEvaluateGetResponseValueUnion interface {
ImplementsAppEvaluateGetResponseValueUnion()
}
func init() {
apijson.RegisterUnion(
reflect.TypeOf((*AppEvaluateGetResponseValueUnion)(nil)).Elem(),
"",
apijson.UnionVariant{
TypeFilter: gjson.String,
Type: reflect.TypeOf(shared.UnionString("")),
},
apijson.UnionVariant{
TypeFilter: gjson.Number,
Type: reflect.TypeOf(shared.UnionFloat(0)),
},
apijson.UnionVariant{
TypeFilter: gjson.True,
Type: reflect.TypeOf(shared.UnionBool(false)),
},
apijson.UnionVariant{
TypeFilter: gjson.False,
Type: reflect.TypeOf(shared.UnionBool(false)),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(AppEvaluateGetResponseValueMap{}),
},
apijson.UnionVariant{
TypeFilter: gjson.JSON,
Type: reflect.TypeOf(AppEvaluateGetResponseValueArray{}),
},
)
}
type AppEvaluateGetResponseValueMap map[string]interface{}
func (r AppEvaluateGetResponseValueMap) ImplementsAppEvaluateGetResponseValueUnion() {}
type AppEvaluateGetResponseValueArray []interface{}
func (r AppEvaluateGetResponseValueArray) ImplementsAppEvaluateGetResponseValueUnion() {}
type AppEvaluateGetParams struct {
// Cloudflare account ID that owns the Flagship app.
AccountID param.Field[string] `path:"account_id" api:"required"`
// The flag key to evaluate.
FlagKey param.Field[string] `query:"flagKey" api:"required"`
// Context targeting key (per OpenFeature spec); used for percentage rollout
// bucketing.
TargetingKey param.Field[string] `query:"targetingKey"`
}
// URLQuery serializes [AppEvaluateGetParams]'s query parameters as `url.Values`.
func (r AppEvaluateGetParams) URLQuery() (v url.Values) {
return apiquery.MarshalWithSettings(r, apiquery.QuerySettings{
ArrayFormat: apiquery.ArrayQueryFormatRepeat,
NestedFormat: apiquery.NestedQueryFormatDots,
})
}

