Skip to content
This repository has been archived by the owner on Oct 11, 2018. It is now read-only.

New() with options #92

Closed
krostar opened this issue Aug 17, 2017 · 2 comments
Closed

New() with options #92

krostar opened this issue Aug 17, 2017 · 2 comments

Comments

@krostar
Copy link

krostar commented Aug 17, 2017

Hi,

I would like to change the tag structs to column in structures tag. How can I set the new tag ? I'd love to see something like this:

structs.WithTag("column").New(something).Map()

or

structs.NewWithOptions(structs.Options{
    Tag: "column",
     Object: something,
}).Map()

What do you think about it ?

@fatih
Copy link
Owner

fatih commented Aug 21, 2017

Hi @krostar . Thanks for the feedback. You can do it like (https://play.golang.org/p/Jw3Uy55unv):

type Server struct {
	Name    string `customz:"server_name"`
	ID      int32  `customz:"server_id"`
	Enabled bool   `customz:"enabled"`
}

s := &Server{
	Name: "New York",
	ID:   789012,
}

st := structs.New(s)
st.TagName = "customz"
m := st.Map()

// access them by the custom tags defined above
fmt.Printf("%#v\n", m["server_name"])
fmt.Printf("%#v\n", m["server_id"])
fmt.Printf("%#v\n", m["enabled"])

@fatih fatih closed this as completed Aug 21, 2017
@krostar
Copy link
Author

krostar commented Aug 21, 2017

Don't know how I missed that in the doc, thx.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants