Giter Site home page Giter Site logo

Comments (2)

Ompluscator avatar Ompluscator commented on May 17, 2024

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.

sgandon avatar sgandon commented on May 17, 2024

thanks a lot for your answer and time

from dynamic-struct.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.