Skip to content

Default struct defaulter

Related tasks

Context

The defaults package defines the Defaulter interface to allow types to define custom logic to set default values. However, a majority of the structs do not require custom logic to set default values.

Change

This MR introduces a SetStructValues function to the defaults package. The new function is meant to allow structs to quickly implement the Defaulter interface.

Example

import (
    "gitlab.com/ignitionrobotics/web/cloudsim/pkg/defaults"
)

type Example struct {
    Value string `default:"example"`
}

func (e *Example) SetDefaults() error {
    return defaults.SetStructValues(e)
}

Other information

Additional documentation

Edited by Alejo Carballude

Merge request reports