dnscontrol/models/t_mx.go
Tom Limoncelli 54de1ff698
NEW PROVIDER: OctoDNS (#309)
* govendor gopkg.in/yaml.v2
* Ignore YAML and BIND test data litter.  Create README.txt files to force git to create subdirectories.
* Update convertzone to also read OctoDNS files
2018-02-27 17:36:47 -05:00

40 lines
981 B
Go

package models
import (
"strconv"
"strings"
"github.com/pkg/errors"
)
// SetTargetMX sets the MX fields.
func (rc *RecordConfig) SetTargetMX(pref uint16, target string) error {
rc.MxPreference = pref
rc.Target = target
if rc.Type == "" {
rc.Type = "MX"
}
if rc.Type != "MX" {
panic("assertion failed: SetTargetMX called when .Type is not MX")
}
return nil
}
// SetTargetMXStrings is like SetTargetMX but accepts strings.
func (rc *RecordConfig) SetTargetMXStrings(pref, target string) error {
u64pref, err := strconv.ParseUint(pref, 10, 16)
if err != nil {
return errors.Wrap(err, "can't parse MX data")
}
return rc.SetTargetMX(uint16(u64pref), target)
}
// SetTargetMXString is like SetTargetMX but accepts one big string.
func (rc *RecordConfig) SetTargetMXString(s string) error {
part := strings.Fields(s)
if len(part) != 2 {
return errors.Errorf("MX value does not contain 2 fields: (%#v)", s)
}
return rc.SetTargetMXStrings(part[0], part[1])
}