diff --git a/cli/module_generate/_templates/go/models/tmpl-module.go b/cli/module_generate/_templates/go/models/tmpl-module.go index 0fd3f8fb179..09ceaaf3b1c 100644 --- a/cli/module_generate/_templates/go/models/tmpl-module.go +++ b/cli/module_generate/_templates/go/models/tmpl-module.go @@ -18,17 +18,30 @@ func init() { } type Config struct { - // Put config attributes here - - /* if your model does not need a config, - replace *Config in the init function with resource.NoNativeConfig */ + /* + Put config attributes here. There should be public/exported fields + with a `json` parameter at the end of each attribute. + + Example config struct: + type Config struct { + Pin string `json:"pin"` + Board string `json:"board"` + MinDeg *float64 `json:"min_angle_deg,omitempty"` + } + + If your model does not need a config, replace *Config in the init + function with resource.NoNativeConfig + */ /* Uncomment this if your model does not need to be validated and has no implicit dependecies. */ // resource.TriviallyValidateConfig - } +// Validate ensures all parts of the config are valid and important fields exist. +// Returns implicit dependencies based on the config. +// The path is the JSON path in your robot's config (not the `Config` struct) to the +// resource being validated; e.g. "components.0". func (cfg *Config) Validate(path string) ([]string, error) { // Add config validation code here return nil, nil diff --git a/cli/module_generate/scripts/tmpl-module b/cli/module_generate/scripts/tmpl-module index d80792d063e..c8b861a7368 100644 --- a/cli/module_generate/scripts/tmpl-module +++ b/cli/module_generate/scripts/tmpl-module @@ -19,17 +19,30 @@ func init() { } type Config struct { - // Put config attributes here - - /* if your model does not need a config, - replace *Config in the init function with resource.NoNativeConfig */ + /* + Put config attributes here. There should be public/exported fields + with a `json` parameter at the end of each attribute. + + Example config struct: + type Config struct { + Pin string `json:"pin"` + Board string `json:"board"` + MinDeg *float64 `json:"min_angle_deg,omitempty"` + } + + If your model does not need a config, replace *Config in the init + function with resource.NoNativeConfig + */ /* Uncomment this if your model does not need to be validated and has no implicit dependecies. */ // resource.TriviallyValidateConfig - } +// Validate ensures all parts of the config are valid and important fields exist. +// Returns implicit dependencies based on the config. +// The path is the JSON path in your robot's config (not the `Config` struct) to the +// resource being validated; e.g. "components.0". func (cfg *Config) Validate(path string) ([]string, error) { // Add config validation code here return nil, nil