Similar to .net attributes in Go -


what similar .net attributes in go lang.

or how achieved ?

perhaps similar mechanism struct tags. not elegant, can evaluated @ runtime , provide metadata on struct members.

from reflect package documentation: type structtag

they used, example, in json , xml encoding custom element names.

for example, using standard json package, have struct field don't want appear in json, field want appear if not empty, , third 1 want refer different name struct's internal name. here's how specify tags:

type foo struct {     bar string `json:"-"` //will not appear in json serialization @     baz string `json:",omitempty"` //will appear in json if not empty     gaz string `json:"fuzz"` //will appear name fuzz, not gaz } 

i'm using document , validate parameters in rest api calls, among other uses.

if keep 'optionally space-separated key:"value"' syntax, can use method of structtag access values of individual keys, in example.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -