Ejemplo n.º 1
0
func Example_json() {
	// -- set an exemplary variable in filesystem
	ioutil.WriteFile(TMPFILE+".json", []byte(`{ "jsonflag": "jsonvalue"}`), 0644)
	flagconf.FileList([]string{TMPFILE + ".json"})
	defer os.Remove(TMPFILE + ".json") // just make sure to remove temporary file
	// ---
	// The default used file is : "~/.flagconf/<PREFIX>.yml"

	//Actual code in main() function:
	flagconf.Parse(PREFIX) // Compared to the flag package, the prefix is the only additional information passed to the parse function.

	fmt.Printf("%s", *jsonflag)

	//Output:
	//jsonvalue
}
Ejemplo n.º 2
0
func Example_fs() {
	// --- set an exemplary variable in filesystem
	ioutil.WriteFile(TMPFILE+".yml", []byte("fsflag: myvalue"), 0644)
	flagconf.FileList([]string{TMPFILE + ".yml"})
	defer os.Remove(TMPFILE + ".yml") // just make sure to remove temporary file
	// ---
	// The default used file is : "~/.flagconf/<PREFIX>.yml"

	//Actual code in main() function:
	flagconf.Parse(PREFIX)
	// the only additional information compared to is the application specific PREFIX t

	fmt.Printf("%s", *fsflag)

	//Output:
	//myvalue
}