File: set.go

package info (click to toggle)
golang-github-clbanning-mxj 2.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,200 kB
  • sloc: xml: 176; makefile: 4
file content (26 lines) | stat: -rw-r--r-- 529 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package mxj

import (
	"strings"
)

// Sets the value for the path
func (mv Map) SetValueForPath(value interface{}, path string) error {
	pathAry := strings.Split(path, ".")
	parentPathAry := pathAry[0 : len(pathAry)-1]
	parentPath := strings.Join(parentPathAry, ".")

	val, err := mv.ValueForPath(parentPath)
	if err != nil {
		return err
	}
	if val == nil {
		return nil // we just ignore the request if there's no val
	}

	key := pathAry[len(pathAry)-1]
	cVal := val.(map[string]interface{})
	cVal[key] = value

	return nil
}