Skip to content

Commit 343f691

Browse files
authored
feat: expose generic resolution/evaluation details structs (#403)
Signed-off-by: Sahid Velji <[email protected]>
1 parent ce1a0f7 commit 343f691

File tree

2 files changed

+30
-49
lines changed

2 files changed

+30
-49
lines changed

openfeature/client.go

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -149,30 +149,24 @@ type EvaluationDetails struct {
149149
ResolutionDetail
150150
}
151151

152-
type BooleanEvaluationDetails struct {
153-
Value bool
152+
// GenericEvaluationDetails represents the result of the flag evaluation process.
153+
type GenericEvaluationDetails[T any] struct {
154+
Value T
154155
EvaluationDetails
155156
}
156157

157-
type StringEvaluationDetails struct {
158-
Value string
159-
EvaluationDetails
160-
}
161-
162-
type FloatEvaluationDetails struct {
163-
Value float64
164-
EvaluationDetails
165-
}
166-
167-
type IntEvaluationDetails struct {
168-
Value int64
169-
EvaluationDetails
170-
}
171-
172-
type InterfaceEvaluationDetails struct {
173-
Value any
174-
EvaluationDetails
175-
}
158+
type (
159+
// BooleanEvaluationDetails represents the result of the flag evaluation process for boolean flags.
160+
BooleanEvaluationDetails = GenericEvaluationDetails[bool]
161+
// StringEvaluationDetails represents the result of the flag evaluation process for string flags.
162+
StringEvaluationDetails = GenericEvaluationDetails[string]
163+
// FloatEvaluationDetails represents the result of the flag evaluation process for float64 flags.
164+
FloatEvaluationDetails = GenericEvaluationDetails[float64]
165+
// IntEvaluationDetails represents the result of the flag evaluation process for int64 flags.
166+
IntEvaluationDetails = GenericEvaluationDetails[int64]
167+
// InterfaceEvaluationDetails represents the result of the flag evaluation process for Object flags.
168+
InterfaceEvaluationDetails = GenericEvaluationDetails[any]
169+
)
176170

177171
type ResolutionDetail struct {
178172
Variant string

openfeature/provider.go

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,6 @@ func (s NoopEventHandler) EventChannel() <-chan Event {
126126
// ProviderResolutionDetail is a structure which contains a subset of the fields defined in the EvaluationDetail,
127127
// representing the result of the provider's flag resolution process
128128
// see https://github.com/open-feature/spec/blob/main/specification/types.md#resolution-details
129-
// N.B we could use generics but to support older versions of go for now we will have type specific resolution
130-
// detail
131129
type ProviderResolutionDetail struct {
132130
ResolutionError ResolutionError
133131
Reason Reason
@@ -156,35 +154,24 @@ func (p ProviderResolutionDetail) Error() error {
156154
return errors.New(p.ResolutionError.Error())
157155
}
158156

159-
// BoolResolutionDetail provides a resolution detail with boolean type
160-
type BoolResolutionDetail struct {
161-
Value bool
157+
// GenericResolutionDetail represents the result of the provider's flag resolution process.
158+
type GenericResolutionDetail[T any] struct {
159+
Value T
162160
ProviderResolutionDetail
163161
}
164162

165-
// StringResolutionDetail provides a resolution detail with string type
166-
type StringResolutionDetail struct {
167-
Value string
168-
ProviderResolutionDetail
169-
}
170-
171-
// FloatResolutionDetail provides a resolution detail with float64 type
172-
type FloatResolutionDetail struct {
173-
Value float64
174-
ProviderResolutionDetail
175-
}
176-
177-
// IntResolutionDetail provides a resolution detail with int64 type
178-
type IntResolutionDetail struct {
179-
Value int64
180-
ProviderResolutionDetail
181-
}
182-
183-
// InterfaceResolutionDetail provides a resolution detail with any type
184-
type InterfaceResolutionDetail struct {
185-
Value any
186-
ProviderResolutionDetail
187-
}
163+
type (
164+
// BoolResolutionDetail represents the result of the provider's flag resolution process for boolean flags.
165+
BoolResolutionDetail = GenericResolutionDetail[bool]
166+
// StringResolutionDetail represents the result of the provider's flag resolution process for string flags.
167+
StringResolutionDetail = GenericResolutionDetail[string]
168+
// FloatResolutionDetail represents the result of the provider's flag resolution process for float64 flags.
169+
FloatResolutionDetail = GenericResolutionDetail[float64]
170+
// IntResolutionDetail represents the result of the provider's flag resolution process for int64 flags.
171+
IntResolutionDetail = GenericResolutionDetail[int64]
172+
// InterfaceResolutionDetail represents the result of the provider's flag resolution process for Object flags.
173+
InterfaceResolutionDetail = GenericResolutionDetail[any]
174+
)
188175

189176
// Metadata provides provider name
190177
type Metadata struct {

0 commit comments

Comments
 (0)