github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/models/t_txt.go (about)

     1  package models
     2  
     3  // SetTargetTXT sets the TXT fields when there is 1 string.
     4  func (rc *RecordConfig) SetTargetTXT(s string) error {
     5  	rc.SetTarget(s)
     6  	rc.TxtStrings = []string{s}
     7  	if rc.Type == "" {
     8  		rc.Type = "TXT"
     9  	}
    10  	if rc.Type != "TXT" {
    11  		panic("assertion failed: SetTargetTXT called when .Type is not TXT")
    12  	}
    13  	return nil
    14  }
    15  
    16  // SetTargetTXTs sets the TXT fields when there are many strings.
    17  func (rc *RecordConfig) SetTargetTXTs(s []string) error {
    18  	rc.SetTarget(s[0])
    19  	rc.TxtStrings = s
    20  	if rc.Type == "" {
    21  		rc.Type = "TXT"
    22  	}
    23  	if rc.Type != "TXT" {
    24  		panic("assertion failed: SetTargetTXT called when .Type is not TXT")
    25  	}
    26  	return nil
    27  }
    28  
    29  // SetTargetTXTString is like SetTargetTXT but accepts one big string,
    30  // which must be parsed into one or more strings based on how it is quoted.
    31  // Ex: foo             << 1 string
    32  //     foo bar         << 1 string
    33  //     "foo" "bar"     << 2 strings
    34  func (rc *RecordConfig) SetTargetTXTString(s string) error {
    35  	return rc.SetTargetTXTs(ParseQuotedTxt(s))
    36  }