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
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() {
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.
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,
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
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.
--