Exemple #1
0
func getConfig(path string) (zhash.Hash, error) {
	var configData map[string]interface{}

	_, err := toml.DecodeFile(path, &configData)
	if err != nil {
		return zhash.Hash{}, err
	}

	return zhash.HashFromMap(configData), nil
}
Exemple #2
0
func getConfig(path string) (zhash.Hash, error) {
	configData := map[string]interface{}{}
	_, err := toml.DecodeFile(path, &configData)
	if err != nil {
		if os.IsNotExist(err) {
			return zhash.NewHash(), err
		}

		return zhash.NewHash(), ser.Errorf(
			err,
			"can't decode toml file: %s",
		)
	}

	return zhash.HashFromMap(configData), nil
}
Exemple #3
0
// Example HashFromMap shows how to initialize your hash from map
func Example_hashFromMap() {
	m := map[string]interface{}{
		"plainValue": 10.1,
		"subMap": map[string]interface{}{
			"elem1": 10,
			"elem2": true,
		},
	}

	h := zhash.HashFromMap(m)

	f, err := h.GetFloat("plainValue")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(f)
	// Output:
	// 10.1
}