Last active
July 10, 2019 20:49
-
-
Save osdrv/09e4e57f25d7cd22fecf2934635b3200 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
package main | |
import ( | |
"encoding/json" | |
"io/ioutil" | |
"log" | |
"os" | |
"github.com/ghodss/yaml" | |
) | |
type A struct { | |
Tag interface{} `json:"tag"` | |
} | |
func main() { | |
if len(os.Args) < 2 { | |
log.Fatalf("missing source file name arg") | |
} | |
source := os.Args[1] | |
data, err := ioutil.ReadFile(source) | |
if err != nil { | |
log.Fatalf("failed to read source file: %s", err) | |
} | |
var a A | |
if err := yaml.Unmarshal(data, &a, func(d *json.Decoder) *json.Decoder { | |
d.UseNumber() | |
return d | |
}); err != nil { | |
log.Fatalf("failed to unmarshal yaml: %s", err) | |
} | |
log.Printf("%+v\n", a) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment