icza / dyno Goto Github PK
View Code? Open in Web Editor NEWPackage dyno is a utility to work with dynamic objects at ease.
License: Apache License 2.0
Package dyno is a utility to work with dynamic objects at ease.
License: Apache License 2.0
Is it possible to handle the input of type case interface{}:
to ConvertMapI2MapS
?
A possible input could be a Struct with one of the fields being map[interface{}]interface{}
type or map[string]interface{}
, etc... For example:
type Config struct {
Type string
Options map[string]interface{} // This can have nested options
}
When the config is loaded from a YAML file that looks like this:
type: file
options:
path: "/foo.txt"
start_position: "beginning"
codec:
type: "default"
the yaml.Unmarshal(data, &config)
loads the content into config
but the Options
contains the nested map elements, like codec
that is an map[interface{}]interface{}
instead of map[string]interface{}
, which leads to the well-known problems, when trying to then use json.Marshal(config)
. I tried doing data, err := json.Marshal(dyno.ConvertMapI2MapS(config))
, but the ConvertMapI2MapS
function does not handle input of type interface{}
, which would be an awesome improvement if it had.
It also has issues when passing in a value that is of a type alias, for example:
type Options map[string]interface{}
However, if explicitly cast to map[string]interface[]
, it happily accepts it.
So this would fail: data, err := json.Marshal(dyno.ConvertMapI2MapS(*config))
, but this would succeed:
var zzz map[string]interface{}
zzz = *config
data, err := json.Marshal(dyno.ConvertMapI2MapS(zzz))
Because of the path cannot be empty, it cant add any new element to the root of the yaml.
say my yaml
field:
test: 123
test2: 12443
filed2: sdfsdf
What is the possibility of adding field3
in the root of the yaml in this case?
Currently, GetString only works with values able to be converted to actual strings.
However, two very common data types in Go are implementations or error
and fmt.Stringer
, which can also be returned as strings. It would be nice to have them also be supported.
I can submit a PR if you think this is a good idea.
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.