mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-13 15:50:51 +00:00
refactor: use switch-case not try-err (#1112)
This commit is contained in:
@@ -97,32 +97,24 @@ func (when *When) IsLocal() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (when *When) UnmarshalYAML(value *yaml.Node) error {
|
func (when *When) UnmarshalYAML(value *yaml.Node) error {
|
||||||
unmarshelAsList := func() error {
|
switch value.Kind {
|
||||||
lst := []Constraint{}
|
case yaml.SequenceNode:
|
||||||
err := value.Decode(&lst)
|
if err := value.Decode(&when.Constraints); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
when.Constraints = lst
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
unmarshelAsDict := func() error {
|
case yaml.MappingNode:
|
||||||
c := Constraint{}
|
c := Constraint{}
|
||||||
err := value.Decode(&c)
|
if err := value.Decode(&c); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
when.Constraints = append(when.Constraints, c)
|
when.Constraints = append(when.Constraints, c)
|
||||||
return nil
|
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("not supported yaml kind: %v", value.Kind)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := unmarshelAsList()
|
return nil
|
||||||
if err != nil {
|
|
||||||
err = unmarshelAsDict()
|
|
||||||
}
|
|
||||||
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match returns true if all constraints match the given input. If a single
|
// Match returns true if all constraints match the given input. If a single
|
||||||
|
Reference in New Issue
Block a user