github.com/flatt-online-training/libcompose@v0.4.0/yaml/external.go (about) 1 package yaml 2 3 // External represents an external network entry in compose file. 4 // It can be a boolean (true|false) or have a name 5 type External struct { 6 External bool 7 Name string 8 } 9 10 // MarshalYAML implements the Marshaller interface. 11 func (n External) MarshalYAML() (interface{}, error) { 12 if n.Name == "" { 13 return n.External, nil 14 } 15 return map[string]interface{}{ 16 "name": n.Name, 17 }, nil 18 } 19 20 // UnmarshalYAML implements the Unmarshaller interface. 21 func (n *External) UnmarshalYAML(unmarshal func(interface{}) error) error { 22 if err := unmarshal(&n.External); err == nil { 23 return nil 24 } 25 var dummyExternal struct { 26 Name string 27 } 28 29 err := unmarshal(&dummyExternal) 30 if err != nil { 31 return err 32 } 33 n.Name = dummyExternal.Name 34 n.External = true 35 36 return nil 37 }