Generate Getters
Getters add one method per selected field to the field’s owning struct.
getters: - name: "metadata" returns: ["json", "label", ":value"] output: prefix: "Metadata" suffix: "" format: "pascal"Every name in returns must refer to a configured element, except the special
:value token.
Return element values
Section titled “Return element values”An element can use any output mode. Getters return its computed string even
when the element uses output.mode: none:
elements: - name: "json" input: mode: "tag" tag_priority: ["json"] output: mode: "none"
getters: - name: "key" returns: ["json"]For a Name string \json:“name”`` field, this produces:
func (_struct *User) KeyName() string { return "name"}Return runtime values
Section titled “Return runtime values”:value returns the actual field value with its declared Go type:
getters: - name: "value" returns: [":value"]func (_struct *User) ValueCreatedAt() time.Time { return _struct.CreatedAt}Constago adds imports required by generated method signatures, including types nested in pointers, slices, maps, channels, functions, and generic type arguments.
Return multiple values
Section titled “Return multiple values”The order in returns becomes the order in the method signature:
elements: - name: "json" input: mode: "tag" tag_priority: ["json"] output: mode: "none" - name: "label" input: mode: "tagThenField" tag_priority: ["title"] output: mode: "none"
getters: - name: "metadata" returns: ["json", "label", ":value"]func (_struct *User) MetadataName() (string, string, string) { return "name", "Name", _struct.Name}If the field’s type is not string, only the :value position changes type.
Method names
Section titled “Method names”Getter output builds a method name from:
output.prefix- the Go field name
output.suffix
The combined name is formatted with camel, pascal, snake, or
snakeUpper.
output: prefix: "Get" suffix: "Metadata" format: "pascal"For DisplayName, the method is GetDisplayNameMetadata.