struct tag
A string in backquotes after a struct field, such as `json:"status"`, that tells encoders like encoding/json how to name or treat that field.
In more detail
Tags keep Go field names idiomatic while the JSON keys stay lowercase and stable. The omitempty option leaves a field out when it holds its zero value. Treat tag names in a published report as part of an API: renaming one breaks consumers.
Example
Status string `json:"status"`Related terms
- encoding/json — Go's standard library package for converting between Go values and JSON text.
- struct field — One named value inside a struct, such as Name or Port, with its own type.
- exported identifier — A name in Go that starts with a capital letter, which makes it visible to code in other packages.
Taught in
- Installing the Go Toolchain — Concurrent Systems Programming with Go
- Parsing JSON with encoding/json — Concurrent Systems Programming with Go
- Exporting Results as JSON — Concurrent Systems Programming with Go