Пример #1
0
func (this Configuration) splitBranchKey(key string) (Configuration, string) {
	var keysplit []string
	var cfg Configuration = this

	if strings.Contains(key, ".") {
		keysplit = util.StringSplitLastN(key, ".", 2)

		if cfg = this.Branch(keysplit[0]).(Configuration); cfg == nil {
			return nil, ""
		}

		key = keysplit[1]
	}

	return cfg, key
}
Пример #2
0
func (this Configuration) Set(name string, value interface{}) (err error) {
	if strings.Contains(name, ".") {
		splitname := util.StringSplitLastN(name, ".", 2)
		var cfg ConfigLibrary
		if cfg, err = this.MakeBranch(splitname[0]); err == nil {
			preval := cfg.Interface(splitname[1], nil)
			if preval != nil {
				if _, ismap := preval.(map[string]interface{}); ismap {
					err = ErrValueIsBranch
				}
			}

			if err == nil {
				switch val := value.(type) {
				case int:
					value = int64(val)
				case int8:
					value = int64(val)
				case int16:
					value = int64(val)
				case int32:
					value = int64(val)
				case uint:
					value = int64(val)
				case uint8:
					value = int64(val)
				case uint16:
					value = int64(val)
				case uint32:
					value = int64(val)
				case float32:
					value = float64(val)
				}
				cfg.Set(splitname[1], value)
			}
		}
	}

	return
}