[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-30 Thread Tahir Hashmi
It would be easier to do: type User struct { Name string `json:"name"` } type PrivateUser struct { User Password string `json:"password"` } See https://play.golang.org/p/2VlGgRlrP1 On Wednesday, November 30, 2016 at 2:42:19 PM UTC+5:30, Mirco Zeiss wrote: > > Maybe I'll just wait for go 1.8 whe

[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-30 Thread Mirco Zeiss
Maybe I'll just wait for go 1.8 where the following is possible, because tags aren't part of types anymore. type PublicUser struct{ Password string `json:"-"` Name string `json:"name"` } type PrivateUser struct{ Password string `json:"password"` Name string `json:"name"` } func main() {

[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-28 Thread Mirco Zeiss
Sorry, but it won't work. I'm using the same marshal method when communicating with my DB as when communicating to my frontend. How can I tell it to sometimes leave out the private fields and sometimes not? On Monday, November 28, 2016 at 6:43:26 AM UTC+1, Mirco Zeiss wrote: > > That might work.

[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-27 Thread Mirco Zeiss
That might work. Thank you! Will try and report back. -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options,

[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-25 Thread derickcyril
This will work for you: type User struct { Name string `json:"name"` PasswordHash string `json:"-", db:"passwordHash"` } Thank you, Derick On Friday, November 25, 2016 at 8:35:13 PM UTC+5:30, Mirco Zeiss wrote: > > Yeah, I know. But how do I keep the private fields when talking to my > dat

[go-nuts] Re: Hide struct fields from frontend code (JSON REST API)

2016-11-25 Thread Mirco Zeiss
Yeah, I know. But how do I keep the private fields when talking to my database? On Friday, November 25, 2016 at 2:04:58 PM UTC+1, Tamás Gulácsi wrote: > > Yoz can create a MarshalJSON method on the struct (type), that filters out > private fields, based on either field name, or a field tag. --