ExperimentFromString parses a comma-separated list of experiment names and returns an Experiment with the appropriate flags set. Experiment names can be prefixed with "no" to explicitly disable them. Unknown experiment names are silently ignored.
(val string)
| 42 | // Experiment names can be prefixed with "no" to explicitly disable them. |
| 43 | // Unknown experiment names are silently ignored. |
| 44 | func ExperimentFromString(val string) Experiment { |
| 45 | e := Experiment{} |
| 46 | if val == "" { |
| 47 | return e |
| 48 | } |
| 49 | |
| 50 | for _, name := range strings.Split(val, ",") { |
| 51 | name = strings.TrimSpace(name) |
| 52 | if name == "" { |
| 53 | continue |
| 54 | } |
| 55 | |
| 56 | // Check if this is a negation (noFoo) |
| 57 | enabled := true |
| 58 | if strings.HasPrefix(strings.ToLower(name), "no") && len(name) > 2 { |
| 59 | // Could be a negation, check if the rest is a valid experiment |
| 60 | possibleExp := name[2:] |
| 61 | if isKnownExperiment(possibleExp) { |
| 62 | name = possibleExp |
| 63 | enabled = false |
| 64 | } |
| 65 | // If not a known experiment, treat "no..." as a potential experiment name itself |
| 66 | } |
| 67 | |
| 68 | setExperiment(&e, name, enabled) |
| 69 | } |
| 70 | |
| 71 | return e |
| 72 | } |
| 73 | |
| 74 | // isKnownExperiment returns true if the given name (case-insensitive) is a |
| 75 | // known experiment. |