From b6ad59dad17667e75f82f23be8af091bb855a849 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 4 Dec 2024 12:31:18 -0500 Subject: [PATCH 1/3] add clarifying comments to config struct and validate --- .../_templates/go/models/tmpl-module.go | 21 +++++++++++++++---- cli/module_generate/scripts/tmpl-module | 21 +++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/cli/module_generate/_templates/go/models/tmpl-module.go b/cli/module_generate/_templates/go/models/tmpl-module.go index 0fd3f8fb179..5a0be5c8bab 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 + /* + Put config attributes here. There should be public/exported fields + with a `json` parameter at the end of each attribute. - /* if your model does not need a config, - replace *Config in the init function with resource.NoNativeConfig */ + If your model does not need a config, replace *Config in the init + function with resource.NoNativeConfig + + Example config struct: + type Config struct { + Pin string `json:"pin"` + Board string `json:"board"` + MinDeg *float64 `json:"min_angle_deg,omitempty"` + } + */ /* 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..c23f1a64b60 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 + /* + Put config attributes here. There should be public/exported fields + with a `json` parameter at the end of each attribute. - /* if your model does not need a config, - replace *Config in the init function with resource.NoNativeConfig */ + If your model does not need a config, replace *Config in the init + function with resource.NoNativeConfig + + Example config struct: + type Config struct { + Pin string `json:"pin"` + Board string `json:"board"` + MinDeg *float64 `json:"min_angle_deg,omitempty"` + } + */ /* 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 From 330f09b05a841b8985b10ae4c2d7cc5a6afccf6c Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 4 Dec 2024 13:26:50 -0500 Subject: [PATCH 2/3] move comments --- cli/module_generate/_templates/go/models/tmpl-module.go | 8 ++++---- cli/module_generate/scripts/tmpl-module | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/module_generate/_templates/go/models/tmpl-module.go b/cli/module_generate/_templates/go/models/tmpl-module.go index 5a0be5c8bab..4a964b99e00 100644 --- a/cli/module_generate/_templates/go/models/tmpl-module.go +++ b/cli/module_generate/_templates/go/models/tmpl-module.go @@ -21,16 +21,16 @@ type Config struct { /* Put config attributes here. There should be public/exported fields with a `json` parameter at the end of each attribute. - - If your model does not need a config, replace *Config in the init - function with resource.NoNativeConfig - + 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 diff --git a/cli/module_generate/scripts/tmpl-module b/cli/module_generate/scripts/tmpl-module index c23f1a64b60..cb643a936c0 100644 --- a/cli/module_generate/scripts/tmpl-module +++ b/cli/module_generate/scripts/tmpl-module @@ -22,16 +22,16 @@ type Config struct { /* Put config attributes here. There should be public/exported fields with a `json` parameter at the end of each attribute. - - If your model does not need a config, replace *Config in the init - function with resource.NoNativeConfig - + 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 From fbd7b09e8258cbe48143fecd7d8191336eb05768 Mon Sep 17 00:00:00 2001 From: purplenicole730 Date: Wed, 4 Dec 2024 13:39:46 -0500 Subject: [PATCH 3/3] make path comment clearer --- cli/module_generate/_templates/go/models/tmpl-module.go | 4 ++-- cli/module_generate/scripts/tmpl-module | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cli/module_generate/_templates/go/models/tmpl-module.go b/cli/module_generate/_templates/go/models/tmpl-module.go index 4a964b99e00..09ceaaf3b1c 100644 --- a/cli/module_generate/_templates/go/models/tmpl-module.go +++ b/cli/module_generate/_templates/go/models/tmpl-module.go @@ -40,8 +40,8 @@ type Config struct { // 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" +// 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 cb643a936c0..c8b861a7368 100644 --- a/cli/module_generate/scripts/tmpl-module +++ b/cli/module_generate/scripts/tmpl-module @@ -41,8 +41,8 @@ type Config struct { // 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" +// 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