github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/github/yaml/container.go (about) 1 package yaml 2 3 import "errors" 4 5 type Container struct { 6 Image string `yaml:"image,omitempty"` 7 Env map[string]string `yaml:"env,omitempty"` 8 Ports []string `yaml:"ports,omitempty"` 9 Volumes []string `yaml:"volumes,omitempty"` 10 Options string `yaml:"options,omitempty"` 11 Credentials *Credentials `yaml:"credentials,omitempty"` 12 } 13 14 func (v *Container) UnmarshalYAML(unmarshal func(interface{}) error) error { 15 var out1 string 16 if err := unmarshal(&out1); err == nil { 17 v.Image = out1 18 return nil 19 } 20 var out2 struct { 21 Image string `yaml:"image,omitempty"` 22 Env map[string]string `yaml:"env,omitempty"` 23 Ports []string `yaml:"ports,omitempty"` 24 Volumes []string `yaml:"volumes,omitempty"` 25 Options string `yaml:"options,omitempty"` 26 Credentials *Credentials `yaml:"credentials,omitempty"` 27 } 28 if err := unmarshal(&out2); err == nil { 29 *v = out2 30 return nil 31 } 32 return errors.New("failed to unmarshal container") 33 }