mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-23 02:11:01 +00:00
e34daae0cf
* Refactor: move cncd/pipeline/ to pipeline/ * Refactor: move pipeline/pipeline/ to pipeline/
38 lines
775 B
Go
38 lines
775 B
Go
package yaml
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
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 Unmarshaller interface.
|
|
func (n *Networks) UnmarshalYAML(value *yaml.Node) error {
|
|
networks := map[string]Network{}
|
|
err := value.Decode(&networks)
|
|
|
|
for key, nn := range networks {
|
|
if nn.Name == "" {
|
|
nn.Name = fmt.Sprintf("%v", key)
|
|
}
|
|
if nn.Driver == "" {
|
|
nn.Driver = "bridge"
|
|
}
|
|
n.Networks = append(n.Networks, &nn)
|
|
}
|
|
return err
|
|
}
|