fatih / structs

Utilities for Go structs

Home Page:http://godoc.org/github.com/fatih/structs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New() with options

krostar opened this issue · comments

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 ?

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"])

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