We were using `yaml.Unmarshal` on basic types or inline structs. This was not efficient and not clear to defined what we expect in labels. We now use types to unmarshal the labels. Only the `values` label is, at this time, parsed by GetValuesFromLabel because this `utils` function is clearly a special case.
15 lines
294 B
Go
15 lines
294 B
Go
package labelStructs
|
|
|
|
import "gopkg.in/yaml.v3"
|
|
|
|
type Ports []uint32
|
|
|
|
// PortsFrom returns a Ports from the given string.
|
|
func PortsFrom(data string) (Ports, error) {
|
|
var mapping Ports
|
|
if err := yaml.Unmarshal([]byte(data), &mapping); err != nil {
|
|
return nil, err
|
|
}
|
|
return mapping, nil
|
|
}
|