...

Source file src/github.com/clbanning/mxj/v2/set.go

Documentation: github.com/clbanning/mxj/v2

     1  package mxj
     2  
     3  import (
     4  	"strings"
     5  )
     6  
     7  // Sets the value for the path
     8  func (mv Map) SetValueForPath(value interface{}, path string) error {
     9  	pathAry := strings.Split(path, ".")
    10  	parentPathAry := pathAry[0 : len(pathAry)-1]
    11  	parentPath := strings.Join(parentPathAry, ".")
    12  
    13  	val, err := mv.ValueForPath(parentPath)
    14  	if err != nil {
    15  		return err
    16  	}
    17  	if val == nil {
    18  		return nil // we just ignore the request if there's no val
    19  	}
    20  
    21  	key := pathAry[len(pathAry)-1]
    22  	cVal := val.(map[string]interface{})
    23  	cVal[key] = value
    24  
    25  	return nil
    26  }
    27  

View as plain text