mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-01-09 00:55:32 +00:00
refactor: use switch-case not try-err (#1112)
This commit is contained in:
parent
5a945c10e9
commit
a46723334b
1 changed files with 9 additions and 17 deletions
|
@ -97,32 +97,24 @@ func (when *When) IsLocal() bool {
|
|||
}
|
||||
|
||||
func (when *When) UnmarshalYAML(value *yaml.Node) error {
|
||||
unmarshelAsList := func() error {
|
||||
lst := []Constraint{}
|
||||
err := value.Decode(&lst)
|
||||
if err != nil {
|
||||
switch value.Kind {
|
||||
case yaml.SequenceNode:
|
||||
if err := value.Decode(&when.Constraints); err != nil {
|
||||
return err
|
||||
}
|
||||
when.Constraints = lst
|
||||
return nil
|
||||
}
|
||||
|
||||
unmarshelAsDict := func() error {
|
||||
case yaml.MappingNode:
|
||||
c := Constraint{}
|
||||
err := value.Decode(&c)
|
||||
if err != nil {
|
||||
if err := value.Decode(&c); err != nil {
|
||||
return err
|
||||
}
|
||||
when.Constraints = append(when.Constraints, c)
|
||||
return nil
|
||||
|
||||
default:
|
||||
return fmt.Errorf("not supported yaml kind: %v", value.Kind)
|
||||
}
|
||||
|
||||
err := unmarshelAsList()
|
||||
if err != nil {
|
||||
err = unmarshelAsDict()
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// Match returns true if all constraints match the given input. If a single
|
||||
|
|
Loading…
Reference in a new issue