forked from docker/libcompose
-
Notifications
You must be signed in to change notification settings - Fork 2
/
external.go
37 lines (32 loc) · 776 Bytes
/
external.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package yaml
// External represents an external network entry in compose file.
// It can be a boolean (true|false) or have a name
type External struct {
External bool
Name string
}
// MarshalYAML implements the Marshaller interface.
func (n External) MarshalYAML() (interface{}, error) {
if n.Name == "" {
return n.External, nil
}
return map[string]interface{}{
"name": n.Name,
}, nil
}
// UnmarshalYAML implements the Unmarshaller interface.
func (n *External) UnmarshalYAML(unmarshal func(interface{}) error) error {
if err := unmarshal(&n.External); err == nil {
return nil
}
var dummyExternal struct {
Name string
}
err := unmarshal(&dummyExternal)
if err != nil {
return err
}
n.Name = dummyExternal.Name
n.External = true
return nil
}