woodpecker/pipeline/frontend/yaml/types/bool.go
6543 fe31fb1e06
Drop error only on purpose or else report back or log (#514)
- Remove Deadcode
- Simplify Code
- Drop error only on purpose
2021-11-23 15:36:52 +01:00

35 lines
557 B
Go

package types
import (
"strconv"
"gopkg.in/yaml.v3"
)
// BoolTrue is a custom Yaml boolean type that defaults to true.
type BoolTrue struct {
value bool
}
// UnmarshalYAML implements custom Yaml unmarshaling.
func (b *BoolTrue) UnmarshalYAML(value *yaml.Node) error {
var s string
if err := value.Decode(&s); err != nil {
return err
}
v, err := strconv.ParseBool(s)
if err == nil {
b.value = !v
}
if s != "" && err != nil {
return err
}
return nil
}
// Bool returns the bool value.
func (b BoolTrue) Bool() bool {
return !b.value
}