joeycumines / go-dotnotation Goto Github PK
View Code? Open in Web Editor NEWA simple dot notation accessor, to get and set values from data structures.
License: Apache License 2.0
A simple dot notation accessor, to get and set values from data structures.
License: Apache License 2.0
Hi, thanks for the package first. I found and issue when I try to set a nested property in a map[string]inteface{}
that is empty.
Think on an empty map and you try to set 'nested.prop' it fail because this line: https://github.com/joeycumines/go-dotnotation/blob/master/dotnotation/accessor.go#L29
return an error because nested
is not there, so I change that with this:
func (p Accessor) Set(target interface{}, key string, value interface{}) error {
properties := p.parser(key)
var targetValue interface{} // added this
for i, property := range properties {
if i == (len(properties) - 1) {
// we reached the last property
return p.setter(target, property, value)
}
// attempt to get the next level, so we can set the last property
var err error
targetValue, err = p.getter(target, property) // assign to targetValue
if err != nil {
nextLevel := make(map[string]interface{}) // create next level as map[string]interface{}
err = p.setter(target, property, nextLevel) // set to current target the next level
target = nextLevel // change the target to nextLevel so next iteration will set on it.
if err != nil {
return err
}
} else {
target = targetValue // let the code follow the idea of original target
}
}
return errors.New("no properties parsed from key: " + key)
}
So basically we are going through an empty map and we will make the middle missing map. If u wish I can make a PR but I'm really new in Go world.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.