Example #1
0
func main() {

	var err error

	cfg := onion.New()

	// Get command line flags
	fs := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
	c_cmd := flagslayer.NewFlagLayer(fs)
	c_cmd.SetString("home", "home", "none", "Set home directory")
	c_cmd.SetBool("enable", "enable", false, "Enable demo")
	c_cmd.SetBool("verbose", "v", false, "More verbose output")
	c_cmd.SetInt64("int", "i", 0, "Integer")
	err = cfg.AddLayer(c_cmd)
	check(err)

	// Load YAML config
	c_yaml := onion.NewFileLayer("config.yaml")
	err = cfg.AddLayer(c_yaml)
	check(err)

	// Load TOML config
	c_toml := onion.NewFileLayer("config.toml")
	err = cfg.AddLayer(c_toml)
	check(err)

	// Get ENV variables
	c_env := onion.NewEnvLayer("HOME", "USER")
	err = cfg.AddLayer(c_env)
	check(err)

	// Print results
	fmt.Println(strings.Repeat("=", 80))

	fmt.Println(cfg.GetBool("enable"))

	fmt.Println(cfg.GetInt("first"))
	fmt.Println(cfg.GetInt("second"))
	fmt.Println(cfg.GetStringSlice("list"))

	fmt.Println(cfg.GetInt("section.first"))
	fmt.Println(cfg.GetInt("section.second"))

	// Case insensitive
	fmt.Println(cfg.GetString("home"))
	fmt.Println(cfg.GetString("Home"))
	fmt.Println(cfg.GetString("HOME"))
	fmt.Println(cfg.GetString("user"))

	fmt.Println(strings.Repeat("-", 80))
}
Example #2
0
func main() {

	conf := onion.New()

	def := onion.NewDefaultLayer()
	err := def.SetDefault("port", 6998)
	panicOnErr(err)

	err = conf.AddLayer(def)
	panicOnErr(err)

	log.Printf("the port is %d (default layer)", conf.GetInt("port"))

	err = conf.AddLayer(onion.NewFileLayer(filepath.Join(pwd(), "test.json")))
	panicOnErr(err)

	log.Printf("the port is %d (file layer)", conf.GetInt("port"))

	err = conf.AddLayer(onion.NewEnvLayer("PORT"))
	panicOnErr(err)

	log.Printf("the final port is %d, Try to set PORT in env and try again", conf.GetInt("port"))
}
Example #3
0
// on arr
type arr [10]int

// on testing
type testing interface {
	Test(string) string
}

// The test is the test
func (m *example) Test(x string) (y string) {
	y = x
	return
}

var o = onion.New()

var j, _ = AnnotatedOne("", 1, 1, 1, example{}, nil, nil)

var s func()

var alal onion.Layer

var js = 10

var im complex64

var pop = [...]int{1, 2, 6}

// Test
func main() {