...

Source file src/github.com/growthbook/growthbook-golang/feature_result.go

Documentation: github.com/growthbook/growthbook-golang

     1  package growthbook
     2  
     3  // FeatureResult is the result of evaluating a feature.
     4  type FeatureResult struct {
     5  	Value            FeatureValue
     6  	Source           FeatureResultSource
     7  	On               bool
     8  	Off              bool
     9  	RuleID           string
    10  	Experiment       *Experiment
    11  	ExperimentResult *Result
    12  }
    13  
    14  // BuildFeatureResult creates an FeatureResult value from a JSON
    15  // object represented as a Go map.
    16  func BuildFeatureResult(dict map[string]interface{}) *FeatureResult {
    17  	result := FeatureResult{}
    18  	for k, v := range dict {
    19  		switch k {
    20  		case "value":
    21  			result.Value = v
    22  		case "on":
    23  			on, ok := jsonBool(v, "FeatureResult", "on")
    24  			if !ok {
    25  				return nil
    26  			}
    27  			result.On = on
    28  		case "off":
    29  			off, ok := jsonBool(v, "FeatureResult", "off")
    30  			if !ok {
    31  				return nil
    32  			}
    33  			result.Off = off
    34  		case "source":
    35  			source, ok := jsonString(v, "FeatureResult", "source")
    36  			if !ok {
    37  				return nil
    38  			}
    39  			result.Source = ParseFeatureResultSource(source)
    40  		case "experiment":
    41  			tmp, ok := v.(map[string]interface{})
    42  			if !ok {
    43  				logError("Invalid JSON data type", "FeatureResult", "experiment")
    44  				continue
    45  			}
    46  			experiment := BuildExperiment(tmp)
    47  			if experiment == nil {
    48  				return nil
    49  			}
    50  			result.Experiment = experiment
    51  		case "experimentResult":
    52  			tmp, ok := v.(map[string]interface{})
    53  			if !ok {
    54  				logError("Invalid JSON data type", "FeatureResult", "experimentResult")
    55  				return nil
    56  			}
    57  			experimentResult := BuildResult(tmp)
    58  			if experimentResult == nil {
    59  				return nil
    60  			}
    61  			result.ExperimentResult = experimentResult
    62  		default:
    63  			logWarn("Unknown key in JSON data", "FeatureResult", k)
    64  		}
    65  	}
    66  	return &result
    67  }
    68  

View as plain text