Been playing around with Google’s Go Lang. Here is something I wasn’t able to figure out obviously.

When marshaling with json only exported fields are encoded. Exported fields in a struct must start with a capital letter. If you want to rename the field and have it be exported. It must be done like so.

type Auth struct {

UserId int “userId”

Comment string “comment”

}

a := Auth{UserId: 52, Comment: “notes about auth”}

b, err := json.Marshal(a)


Comments

Name (required)

Email (required)

Website

Speak your mind