1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-02-04 18:21:06 +02:00

39 lines
774 B
Go
Raw Normal View History

2017-03-05 18:56:08 +11:00
package yaml
import (
"fmt"
2019-11-14 20:16:03 +01:00
"gopkg.in/yaml.v3"
2017-03-05 18:56:08 +11:00
)
type (
// Networks defines a collection of networks.
Networks struct {
Networks []*Network
}
// Network defines a container network.
Network struct {
Name string `yaml:"name,omitempty"`
Driver string `yaml:"driver,omitempty"`
DriverOpts map[string]string `yaml:"driver_opts,omitempty"`
}
)
// UnmarshalYAML implements the Unmarshaler interface.
2019-11-14 20:16:03 +01:00
func (n *Networks) UnmarshalYAML(value *yaml.Node) error {
networks := map[string]Network{}
err := value.Decode(&networks)
2017-03-05 18:56:08 +11:00
2019-11-14 20:16:03 +01:00
for key, nn := range networks {
2017-03-05 18:56:08 +11:00
if nn.Name == "" {
2019-11-14 20:16:03 +01:00
nn.Name = fmt.Sprintf("%v", key)
2017-03-05 18:56:08 +11:00
}
if nn.Driver == "" {
nn.Driver = "bridge"
}
n.Networks = append(n.Networks, &nn)
}
return err
}