Пример #1
0
func main() {
	flag.Parse()
	url := flag.Arg(0)

	var m *jsonutils.Model

	if *filename != "" {
		b, err := ioutil.ReadFile(*filename)
		if err != nil {
			log.Fatal(err)
		}
		s := strings.Split(*filename, ".")
		m, err = jsonutils.FromBytes(b, s[0])
		if err != nil {
			log.Fatal(err)
		}
	} else if url != "" {
		var err error
		m, err = jsonutils.GetModel(url)
		if err != nil {
			log.Fatal(err.Error())
		}
	} else {
		b, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			log.Fatal(err)
		}
		m, err = jsonutils.FromBytes(b, "")
		if err != nil {
			log.Fatal(err)
		}
	}

	m.WithExample = *withExamples
	if *asJava {
		m.WriteJava()
	} else {
		m.WriteGo()
	}
}
Пример #2
0
func main() {
	flag.Parse()
	url := flag.Arg(0)

	var m *jsonutils.Model
	var err error
	var data []byte
	var name string

	if *filename != "" {
		name = strings.Split(*filename, ".")[0]
		data, err = ioutil.ReadFile(*filename)
	} else if url != "" {
		data, name, err = jsonutils.Get(url)
	} else {
		data, err = ioutil.ReadAll(os.Stdin)
	}
	if err != nil {
		log.Fatal(err)
	}

	if !*isYaml {
		m, err = jsonutils.FromBytes(data, strings.Title(name))
		if err != nil {
			log.Fatal(err)
		}
	} else {
		var f map[string]interface{}
		err = yaml.Unmarshal(data, &f)
		if err != nil {
			log.Fatal("goyaml.Unmarshal:", err)
		}
		m = jsonutils.New(f, strings.Title(name))
	}

	m.WithExample = *withExamples
	m.Convert = *convertString
	if *asJava {
		m.WriteJava()
	} else {
		m.WriteGo()
	}
}