mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Refactor RecordConfig: Add getters/setters (#314)
* Replace RecordConfig.Name and .NameFQDN with getters and setters. * Replace RecordConfig.Target with getters and setters. * Eliminate the CombinedTarget concept. * Add RecordConfig.PopulateFromString to reduce code in all providers. * encode and decode name.com txt records (#315) * Replace fmt.Errorf with errors.Errorf
This commit is contained in:
35
models/t_txt.go
Normal file
35
models/t_txt.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package models
|
||||
|
||||
// SetTargetTXT sets the TXT fields when there is 1 string.
|
||||
func (rc *RecordConfig) SetTargetTXT(s string) error {
|
||||
rc.Target = s
|
||||
rc.TxtStrings = []string{s}
|
||||
if rc.Type == "" {
|
||||
rc.Type = "TXT"
|
||||
}
|
||||
if rc.Type != "TXT" {
|
||||
panic("assertion failed: SetTargetTXT called when .Type is not TXT")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetTargetTXTs sets the TXT fields when there are many strings.
|
||||
func (rc *RecordConfig) SetTargetTXTs(s []string) error {
|
||||
rc.Target = s[0]
|
||||
rc.TxtStrings = s
|
||||
if rc.Type == "" {
|
||||
rc.Type = "TXT"
|
||||
}
|
||||
if rc.Type != "TXT" {
|
||||
panic("assertion failed: SetTargetTXT called when .Type is not TXT")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetTargetTXTString is like SetTargetTXT but accepts one big string.
|
||||
// Ex: foo << 1 string
|
||||
// foo bar << 1 string
|
||||
// "foo" "bar" << 2 strings
|
||||
func (rc *RecordConfig) SetTargetTXTString(s string) error {
|
||||
return rc.SetTargetTXTs(ParseQuotedTxt(s))
|
||||
}
|
Reference in New Issue
Block a user