2019-02-10 19:00:16 +00:00
|
|
|
// Copyright 2019 Drone.IO Inc. All rights reserved.
|
2019-02-21 20:48:45 +00:00
|
|
|
// Use of this source code is governed by the Drone Non-Commercial License
|
|
|
|
// that can be found in the LICENSE file.
|
2019-02-10 19:00:16 +00:00
|
|
|
|
2019-01-22 23:44:17 +00:00
|
|
|
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
|
|
|
|
}
|