示例#1
0
func procArgs() {
	flag.Usage = usage
	json5Path := flag.String("c", "", "path/to/file.json5")
	outputPath := flag.String("o", "", "path/to/file.json")
	flag.Parse()
	if *json5Path == "" {
		usage()
	}
	file, err := os.Open(*json5Path)
	if err != nil {
		fmt.Println(err)
		usage()
	}

	var data interface{}
	dec := json5.NewDecoder(file)
	err = dec.Decode(&data)
	if err != nil {
		fmt.Println(err)
		usage()
	}
	b, err := json.MarshalIndent(data, "", "    ")
	if err != nil {
		fmt.Println(err)
		usage()
	}
	if *outputPath == "" {
		fmt.Println(string(b))
	}
	ioutil.WriteFile(*outputPath, b, 0644)
}
示例#2
0
func parseIsolate(content []byte) (*isolate, error) {
	isolate := &isolate{}
	// TODO(tandrii): figure out why decoding directly into isolate
	// doesn't work.
	// if err := json5.NewDecoder(json5src).Decode(isolate); err != nil {
	var data interface{}
	if err := json5.NewDecoder(convertIsolateToJSON5(content)).Decode(&data); err != nil {
		return nil, err
	}
	buf, _ := json.Marshal(&data)
	if err := json.Unmarshal(buf, isolate); err != nil {
		return nil, err
	}
	return isolate, nil
}