Skip to content

Commit

Permalink
RSDK-9266: improve comments in golang module templates (#4600)
Browse files Browse the repository at this point in the history
  • Loading branch information
purplenicole730 authored Dec 5, 2024
1 parent 3df294c commit 2496627
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
23 changes: 18 additions & 5 deletions cli/module_generate/_templates/go/models/tmpl-module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 18 additions & 5 deletions cli/module_generate/scripts/tmpl-module
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2496627

Please sign in to comment.