Comments (2)
Hi, thx for submitting an issue. After investigation, I've succeeded to have working code, by adapting a line:
// Notice, there is no "&" in front "dataResource"
if err := yaml.Unmarshal([]byte(data), dataResource); err != nil {
fmt.Println(err.Error())
}
This was result in console:
(*struct { Name string "yaml:\"name\""; ContentType string "yaml:\"content-type\""; Data main.DataResource "yaml:\"data\"" })(0xc00008a630)({
Name: (string) (len=3) "foo",
ContentType: (string) (len=34) "application/vnd.talend.iam-account",
Data: (main.DataResource) {
Key: (string) (len=5) "value"
}
})
Name foo
Package dynamic-struct relies on method reflect.New during delivering of new instance of struct, which returns pointer to new zero value. Packages "encoding/json" and "github.com/go-playground/form" still require to pass values as references while decoding/unmarshaling, but some packages like "github.com/leebenson/conform" or "gopkg.in/yaml.v3" accepts those values to be passed as non-references (as, in general, they are already created as such, from builder).
To make a general solution here would require more time for investigation, and to be honest - I'm not 100% sure that solution which supports all cases with same way of value passing for decoding/unmarshaling can be provided (personally, I had a lot of problems dealing with combination of "github.com/go-playground/form" and "github.com/leebenson/conform").
So, I would suggest to use code example which I've added on top.
from dynamic-struct.
thanks a lot for your answer and time
from dynamic-struct.
Related Issues (20)
- Can't add more than 1 field with same type HOT 1
- provide types(string,int etc) directly in place of instance of types HOT 1
- Builder to allow add field and build in different statement HOT 2
- convert interface to struct HOT 2
- Custom structure of array type HOT 1
- Thank you for this package! HOT 1
- Struct fields are in random order HOT 2
- Non deterministic HOT 3
- can support sqlx? HOT 1
- I can use to "encoding/xml"? HOT 1
- Support embedded dynamic struct HOT 2
- Can we generate struct into struct?
- How to change a type of a field HOT 1
- Can we assign a structure variable to a structure field HOT 1
- Error: unreadable: could not resolve interface type HOT 2
- use with sqlx and mysql HOT 1
- Need Capacity as a input to NewSliceOfStructs()
- Expose anonymous/embedded struct member. HOT 3
- Replace current Struct? HOT 1
- Can I cast to a dynamic struct? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dynamic-struct.