Skip to content

Commit

Permalink
fix value type: use interface{} (#60)
Browse files Browse the repository at this point in the history
* fix value type: use interface{}

* bump engine-test-data: to include different types
  • Loading branch information
gagantrivedi committed Feb 1, 2023
1 parent 6880ad7 commit 473dd0d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion flagengine/engine-test-data
11 changes: 5 additions & 6 deletions flagengine/features/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"sort"
"strconv"
"strings"

"github.com/Flagsmith/flagsmith-go-client/v2/flagengine/utils"
)
Expand All @@ -25,7 +24,7 @@ type FeatureStateModel struct {
DjangoID int `json:"django_id"`
FeatureStateUUID string `json:"featurestate_uuid"`
MultivariateFeatureStateValues []*MultivariateFeatureStateValueModel `json:"multivariate_feature_state_values"`
RawValue string `json:"feature_state_value"`
RawValue interface{} `json:"feature_state_value"`
}

func (fs *FeatureStateModel) UnmarshalJSON(bytes []byte) error {
Expand All @@ -36,7 +35,7 @@ func (fs *FeatureStateModel) UnmarshalJSON(bytes []byte) error {
DjangoID int `json:"django_id"`
FeatureStateUUID string `json:"featurestate_uuid"`
MultivariateFeatureStateValues []*MultivariateFeatureStateValueModel `json:"multivariate_feature_state_values"`
RawValue json.RawMessage `json:"feature_state_value"`
RawValue interface{} `json:"feature_state_value"`
}

err := json.Unmarshal(bytes, &obj)
Expand All @@ -50,13 +49,13 @@ func (fs *FeatureStateModel) UnmarshalJSON(bytes []byte) error {
fs.DjangoID = obj.DjangoID
fs.FeatureStateUUID = obj.FeatureStateUUID
fs.MultivariateFeatureStateValues = obj.MultivariateFeatureStateValues
fs.RawValue = strings.Trim(string(obj.RawValue), `"`)
fs.RawValue = obj.RawValue
return nil
}

type MultivariateFeatureOptionModel struct {
ID int `json:"id"`
Value string `json:"value"`
ID int `json:"id"`
Value interface{} `json:"value"`
}

type MultivariateFeatureStateValueModel struct {
Expand Down

0 comments on commit 473dd0d

Please sign in to comment.