golang appengine传出json

So I run golang appengine with go endpoints package ...

I use structs to marshal and un marshal my json incoming requests and out going responses ..

type BusinessWorker struct {
    Wid   string `json:"wid" datastore:"Worker_id" endpoints:"req,desc=Worker id. string value"`
    Phone string `json:"phone" datastore:"Phone" endpoints:"req,desc=Worker phone number. string value"`
}

So as you can see after I validate the data this obj is saved or loaded to/from the datastore ..

My question is .. there are many cases I dont want to respond with all my data that is saved in the datastore .. is there some sort of attribute that I can give to the param that i dont wanna include in my response only in my incoming requests ?

It seems so elementary .. and I cant find it .. ?

Maybe you would like to try one or a combination of the following approaches:

  • Tag of "-" so that the field is ignored. e.g. json:"-"
  • omitempty can be included in your 'json:' and will cause the field not to be included in the resulting json. So you could set the fields you want to hide to nil, prior to serializing to json. e.g. json:"myName,omitempty"
  • copier - there are some projects like: jinzhu's copier that would allow you to copy your entity to a simplified structure, or you could roll your own. (a combination of JSON un-marshalling and marshalling can produce similar results).

For more details about the JSON package see Golang Json marshal docs