mirror of
https://github.com/thegeeklab/drone-yaml.git
synced 2024-11-14 14:30:40 +00:00
33 lines
596 B
Go
33 lines
596 B
Go
|
package yaml
|
||
|
|
||
|
import "strings"
|
||
|
|
||
|
// SliceMap represents a slice or map of key pairs.
|
||
|
type SliceMap struct {
|
||
|
Map map[string]string
|
||
|
}
|
||
|
|
||
|
// UnmarshalYAML implements custom Yaml unmarshaling.
|
||
|
func (s *SliceMap) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||
|
s.Map = map[string]string{}
|
||
|
err := unmarshal(&s.Map)
|
||
|
if err == nil {
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
var slice []string
|
||
|
err = unmarshal(&slice)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
for _, v := range slice {
|
||
|
parts := strings.SplitN(v, "=", 2)
|
||
|
if len(parts) == 2 {
|
||
|
key := parts[0]
|
||
|
val := parts[1]
|
||
|
s.Map[key] = val
|
||
|
}
|
||
|
}
|
||
|
return nil
|
||
|
}
|