-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add reason and errorCode from open-feature (#269)
- Loading branch information
1 parent
96db56d
commit 6e9af48
Showing
14 changed files
with
441 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package flag | ||
|
||
// ErrorCode is an enum following the open-feature specs about error code. | ||
type ErrorCode = string | ||
|
||
const ( | ||
ErrorCodeProviderNotReady ErrorCode = "PROVIDER_NOT_READY" | ||
ErrorCodeFlagNotFound ErrorCode = "FLAG_NOT_FOUND" | ||
ErrorCodeParseError ErrorCode = "PARSE_ERROR" | ||
ErrorCodeTypeMismatch ErrorCode = "TYPE_MISMATCH" | ||
ErrorCodeGeneral ErrorCode = "GENERAL" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package flag | ||
|
||
type EvaluationContext struct { | ||
// Environment is the name of your current env | ||
// this value will be added to the custom information of your user and, | ||
// it will allow to create rules based on this environment, | ||
Environment string | ||
|
||
// DefaultSdkValue is the default value of the SDK when calling the variation. | ||
DefaultSdkValue interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package flag | ||
|
||
type ResolutionDetails struct { | ||
// Variant indicates the name of the variant used when evaluating the flag | ||
Variant string | ||
|
||
// Reason indicates the reason of the decision | ||
Reason ResolutionReason | ||
|
||
// ErrorCode indicates the error code for this evaluation | ||
ErrorCode string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package flag | ||
|
||
// ResolutionReason is an enum following the open-feature specs about resolution reasons. | ||
type ResolutionReason = string | ||
|
||
const ( | ||
// ReasonTargetingMatch Indicates that the feature flag is targeting | ||
// 100% of the targeting audience, | ||
// e.g. 100% rollout percentage | ||
ReasonTargetingMatch ResolutionReason = "TARGETING_MATCH" | ||
|
||
// ReasonSplit Indicates that the feature flag is targeting | ||
// a subset of the targeting audience, | ||
// e.g. less than 100% rollout percentage | ||
ReasonSplit ResolutionReason = "SPLIT" | ||
|
||
// ReasonDisabled Indicates that the feature flag is disabled | ||
ReasonDisabled ResolutionReason = "DISABLED" | ||
|
||
// ReasonDefault Indicates that the feature flag evaluated to the default value | ||
ReasonDefault ResolutionReason = "DEFAULT" | ||
|
||
// ReasonStatic Indicates that the feature flag evaluated to a | ||
// static value, for example, the default value for the flag | ||
// | ||
// Note: Typically means that no dynamic evaluation has been | ||
// executed for the feature flag | ||
ReasonStatic ResolutionReason = "STATIC" | ||
|
||
// ReasonUnknown Indicates an unknown issue occurred during evaluation | ||
ReasonUnknown ResolutionReason = "UNKNOWN" | ||
|
||
// ReasonError Indicates that an error occurred during evaluation | ||
// Note: The `errorCode`-field contains the details of this error | ||
ReasonError ResolutionReason = "ERROR" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,16 @@ | ||
package flagstate | ||
|
||
import ( | ||
"time" | ||
"github.com/thomaspoignant/go-feature-flag/internal/flag" | ||
) | ||
|
||
// NewFlagState is creating a state for a flag. | ||
func NewFlagState( | ||
trackEvents bool, | ||
value interface{}, | ||
variationType string, | ||
failed bool, | ||
) FlagState { | ||
return FlagState{ | ||
Value: value, | ||
Timestamp: time.Now().Unix(), | ||
VariationType: variationType, | ||
Failed: failed, | ||
TrackEvents: trackEvents, | ||
} | ||
} | ||
|
||
// FlagState represents the state of an individual feature flag, with regard to a specific user, when it was called. | ||
type FlagState struct { | ||
Value interface{} `json:"value"` | ||
Timestamp int64 `json:"timestamp"` | ||
VariationType string `json:"variationType"` | ||
TrackEvents bool `json:"trackEvents"` | ||
Failed bool `json:"-"` | ||
Value interface{} `json:"value"` | ||
Timestamp int64 `json:"timestamp"` | ||
VariationType string `json:"variationType"` | ||
TrackEvents bool `json:"trackEvents"` | ||
Failed bool `json:"-"` | ||
ErrorCode flag.ErrorCode `json:"errorCode"` | ||
Reason flag.ResolutionReason `json:"reason"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.