Created
March 20, 2017 19:45
-
-
Save smothiki/5eb2bff12a2ff38e4f04d5211134b6c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func ParseConstraints(data []byte) ([]types.Constraint, error) { | |
var constraints []types.Constraint | |
var dat map[string][]map[string]string | |
if err := json.Unmarshal(data, &dat); err != nil { | |
return nil, err | |
} | |
val, ok := dat["constraint"] | |
if !ok { | |
return nil, nil | |
} | |
for _, mapv := range val { | |
for k, v := range mapv { | |
if strings.Contains(v, "limit") { | |
value, err := strconv.Atoi(strings.Split(v, ":")[1]) | |
if err != nil { | |
return nil, err | |
} | |
constraints = append(constraints, types.Constraint{ConstraintType: "limit", Key: k, Value: value}) | |
} | |
constraints = append(constraints, types.Constraint{ConstraintType: "value", Key: k, Value: v}) | |
} | |
} | |
return constraints, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment