Skip to content

Instantly share code, notes, and snippets.

@osdrv
Last active July 10, 2019 20:49
Show Gist options
  • Save osdrv/09e4e57f25d7cd22fecf2934635b3200 to your computer and use it in GitHub Desktop.
Save osdrv/09e4e57f25d7cd22fecf2934635b3200 to your computer and use it in GitHub Desktop.
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