Generate Elements
An element defines one value derived for every selected struct field.
elements: - name: "json" input: mode: "tag" tag_priority: ["json"] output: mode: "constant"Input modes
Section titled “Input modes”Uses the first non-empty tag in tag_priority. If no listed tag exists, the
element is omitted for that field.
input: mode: "tag" tag_priority: ["db", "json"]For json:"display_name,omitempty", Constago uses display_name; tag options
after the first comma are removed.
Always derives the value from the Go field name. tag_priority receives its
normal default when omitted, but it is not consulted in this mode.
input: mode: "field" tag_priority: ["field"]tagThenField
Section titled “tagThenField”Uses the first tag match, then falls back to the field name.
input: mode: "tagThenField" tag_priority: ["json"]Output modes
Section titled “Output modes”Given:
type User struct { DisplayName string `json:"display_name"`}constant
Section titled “constant”output: mode: "constant" format: prefix: "Json"Generates:
const JsonUserDisplayName = "display_name"struct
Section titled “struct”This mode generates an initialized package variable with a grouped anonymous struct:
output: mode: "struct" format: prefix: "Json"var JsonUser = struct { DisplayName string}{ DisplayName: "display_name",}Use it as JsonUser.DisplayName.
No standalone constant or grouped variable is emitted. The value remains
available to getters that list the element in returns.
Identifier formatting
Section titled “Identifier formatting”The element’s format controls generated names:
format: holder: "pascal" struct: "pascal" prefix: "Json" suffix: "Key"holderformats fields inside grouped accessor variables.structformats top-level constant names and grouped accessor variable names.prefixandsuffixwrap the struct and field portions.- Formats are
camel,pascal,snake, andsnakeUpper.
With prefix: Json, suffix: Key, and struct: snakeUpper, the constant for
User.DisplayName is JSON_USER_DISPLAY_NAME_KEY.
Transform values
Section titled “Transform values”Transforms affect the generated string value, not its Go identifier:
transform: tag_values: true value_case: "upper" value_separator: "_"tag_values: falseleaves tag-derived values unchanged.- Field-name fallbacks are always transformed.
value_caseacceptsasIs,camel,pascal,upper, orlower.value_separatorjoins detected words with the configured string.
For a DisplayName field, lower plus _ produces display_name.