feat: handle []string or string for pathAlias
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m52s
All checks were successful
Build and Push Server / build-and-push (push) Successful in 2m52s
This commit is contained in:
@@ -8,21 +8,21 @@ import (
|
||||
)
|
||||
|
||||
type yamlBlock struct {
|
||||
Path string `yaml:"path"`
|
||||
Codec string `yaml:"codec"`
|
||||
Value any `yaml:"value,omitempty"`
|
||||
Fields []yamlField `yaml:"fields"`
|
||||
ListTemplate string `yaml:"listTemplate,omitempty"`
|
||||
Hidden bool `yaml:"hidden,omitempty"`
|
||||
PathAlias []string `yaml:"pathAlias,omitempty"`
|
||||
Path string `yaml:"path"`
|
||||
Codec string `yaml:"codec"`
|
||||
Value any `yaml:"value,omitempty"`
|
||||
Fields []yamlField `yaml:"fields"`
|
||||
ListTemplate string `yaml:"listTemplate,omitempty"`
|
||||
Hidden bool `yaml:"hidden,omitempty"`
|
||||
PathAlias StringOrSlice `yaml:"pathAlias,omitempty"`
|
||||
}
|
||||
|
||||
type yamlField struct {
|
||||
Path string `yaml:"path"`
|
||||
Value any `yaml:"value,omitempty"`
|
||||
Codec string `yaml:"codec"`
|
||||
Hidden bool `yaml:"hidden,omitempty"`
|
||||
PathAlias []string `yaml:"pathAlias,omitempty"`
|
||||
Path string `yaml:"path"`
|
||||
Value any `yaml:"value,omitempty"`
|
||||
Codec string `yaml:"codec"`
|
||||
Hidden bool `yaml:"hidden,omitempty"`
|
||||
PathAlias StringOrSlice `yaml:"pathAlias,omitempty"`
|
||||
}
|
||||
|
||||
func parseYamlTemplate(input Slice) (block Block, err error) {
|
||||
|
||||
31
template/yaml_types.go
Normal file
31
template/yaml_types.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package template
|
||||
|
||||
import "errors"
|
||||
|
||||
type StringOrSlice []string
|
||||
|
||||
func (s *StringOrSlice) UnmarshalYAML(unmarshal func(any) error) error {
|
||||
var single string
|
||||
if err := unmarshal(&single); err == nil {
|
||||
if single == "" {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
*s = []string{single}
|
||||
return nil
|
||||
}
|
||||
|
||||
var multi []string
|
||||
if err := unmarshal(&multi); err == nil {
|
||||
*s = multi
|
||||
return nil
|
||||
}
|
||||
|
||||
var nothing *struct{}
|
||||
if err := unmarshal(¬hing); err == nil {
|
||||
*s = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.New("expected string, []string, or null")
|
||||
}
|
||||
Reference in New Issue
Block a user