This commit is contained in:
crusader 2018-04-10 17:37:50 +09:00
parent 1cf977be25
commit 1fa0d75103

View File

@ -11,12 +11,16 @@ import (
// SetValueWithJSONStringArray set the value of json string array // SetValueWithJSONStringArray set the value of json string array
// raw([]byte) is ["1", {"a": 1}, [1, 2]] // raw([]byte) is ["1", {"a": 1}, [1, 2]]
// targets([]interface{}) is array of pointer ex) *int, *string, *[], *map, *struct // targets([]interface{}) is array of pointer ex) *int, *string, *[], *map, *struct
func SetValueWithJSONStringArray(raw []byte, targets []interface{}) error { func SetValueWithJSONStringArrayBytes(raw []byte, targets []interface{}) error {
var values []string var values []string
if err := json.Unmarshal(raw, &values); err != nil { if err := json.Unmarshal(raw, &values); err != nil {
return err return err
} }
return SetValueWithJSONStringArray(values, targets)
}
func SetValueWithJSONStringArray(values []string, targets []interface{}) error {
if len(targets) != len(values) { if len(targets) != len(values) {
return fmt.Errorf("Count of raw[%d] and targets[%d] is not same", len(values), len(targets)) return fmt.Errorf("Count of raw[%d] and targets[%d] is not same", len(values), len(targets))
} }