mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-06-04 22:49:34 +00:00
fe31fb1e06
- Remove Deadcode - Simplify Code - Drop error only on purpose
35 lines
557 B
Go
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
|
|
}
|