mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-11-10 17:26:10 +08:00
825ba2d081
* Replaced errors.Wrap with fmt.Errorf (#589) * Find: errors\.Wrap\(([^,]+),\s+(["`][^"`]*)(["`])\) Replace: fmt.Errorf($2: %w$3, $1) * Replaced errors.Wrapf with fmt.Errorf (#589) * Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])\) Replace: fmt.Errorf($2: %w$3, $1) * Find: errors\.Wrapf\(([^,]+),\s+(["`][^"`]*)(["`])(,[^)]+)\) * Replace: fmt.Errorf($2: %w$3$4, $1) * Replaced errors.Errorf with fmt.Errorf (#589) * Find: errors\.Errorf Replace: fmt.Errorf * Cleaned up remaining imports * Cleanup * Regenerate provider support matrix This was broken by #533 ... and it's now the third time this has been missed.
38 lines
964 B
Go
38 lines
964 B
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// SetTargetMX sets the MX fields.
|
|
func (rc *RecordConfig) SetTargetMX(pref uint16, target string) error {
|
|
rc.MxPreference = pref
|
|
rc.SetTarget(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 fmt.Errorf("can't parse MX data: %w", err)
|
|
}
|
|
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 fmt.Errorf("MX value does not contain 2 fields: (%#v)", s)
|
|
}
|
|
return rc.SetTargetMXStrings(part[0], part[1])
|
|
}
|