github.com/teknogeek/dnscontrol/v2@v2.10.1-0.20200227202244-ae299b55ba42/models/t_naptr.go (about) 1 package models 2 3 import ( 4 "fmt" 5 "strconv" 6 "strings" 7 ) 8 9 // SetTargetNAPTR sets the NAPTR fields. 10 func (rc *RecordConfig) SetTargetNAPTR(order uint16, preference uint16, flags string, service string, regexp string, target string) error { 11 rc.NaptrOrder = order 12 rc.NaptrPreference = preference 13 rc.NaptrFlags = flags 14 rc.NaptrService = service 15 rc.NaptrRegexp = regexp 16 rc.SetTarget(target) 17 18 if rc.Type == "" { 19 rc.Type = "NAPTR" 20 } 21 if rc.Type != "NAPTR" { 22 panic("assertion failed: SetTargetNAPTR called when .Type is not NAPTR") 23 } 24 25 return nil 26 } 27 28 // SetTargetNAPTRStrings is like SetTargetNAPTR but accepts strings. 29 func (rc *RecordConfig) SetTargetNAPTRStrings(order, preference, flags string, service string, regexp string, target string) error { 30 i64order, err := strconv.ParseUint(order, 10, 16) 31 if err != nil { 32 return fmt.Errorf("NAPTR order does not fit in 16 bits: %w", err) 33 } 34 i64preference, err := strconv.ParseUint(preference, 10, 16) 35 if err != nil { 36 return fmt.Errorf("NAPTR preference does not fit in 16 bits: %w", err) 37 } 38 return rc.SetTargetNAPTR(uint16(i64order), uint16(i64preference), flags, service, regexp, target) 39 } 40 41 // SetTargetNAPTRString is like SetTargetNAPTR but accepts one big string. 42 func (rc *RecordConfig) SetTargetNAPTRString(s string) error { 43 part := strings.Fields(s) 44 if len(part) != 6 { 45 return fmt.Errorf("NAPTR value does not contain 6 fields: (%#v)", s) 46 } 47 return rc.SetTargetNAPTRStrings(part[0], part[1], part[2], part[3], part[4], StripQuotes(part[5])) 48 }