| 1 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 2 |
// Use of this source code is governed by a BSD-style |
| 3 |
// license that can be found in the LICENSE file. |
| 4 |
|
| 5 |
package a |
| 6 |
|
| 7 |
import ( |
| 8 |
"errors" |
| 9 |
"strings" |
| 10 |
) |
| 11 |
|
| 12 |
var G interface{} |
| 13 |
|
| 14 |
func Unmarshal(data []byte, o interface{}) error { |
| 15 |
G = o |
| 16 |
v, ok := o.(*map[string]interface{}) |
| 17 |
if !ok { |
| 18 |
return errors.New("eek") |
| 19 |
} |
| 20 |
vals := make(map[string]interface{}) |
| 21 |
s := string(data) |
| 22 |
items := strings.Split(s, " ") |
| 23 |
var err error |
| 24 |
for _, item := range items { |
| 25 |
vals[item] = s |
| 26 |
if item == "error" { |
| 27 |
err = errors.New("ouch") |
| 28 |
} |
| 29 |
} |
| 30 |
*v = vals |
| 31 |
return err |
| 32 |
} |