Split long TXT values in 255 strings
This commit is contained in:
parent
63442acdb2
commit
b1881f90d4
1 changed files with 35 additions and 0 deletions
|
|
@ -58,6 +58,30 @@ func GetTomlZones() ([]TomlZone, error) {
|
|||
zone.DefaultTTL = 3600
|
||||
}
|
||||
|
||||
for index, record := range zone.TomlRecords {
|
||||
if !strings.EqualFold(record.Type, "TXT") || len(record.Value) <= 255 {
|
||||
continue
|
||||
}
|
||||
|
||||
var newValue string
|
||||
var split string
|
||||
for count, char := range record.Value {
|
||||
split = fmt.Sprintf("%s%c", split, char)
|
||||
|
||||
if (count+1)%255 == 0 || (count+1) == len(record.Value) {
|
||||
if newValue == "" {
|
||||
newValue = fmt.Sprintf("\"%s\"", split)
|
||||
} else {
|
||||
newValue = fmt.Sprintf("%s \"%s\"", newValue, split)
|
||||
}
|
||||
|
||||
split = ""
|
||||
}
|
||||
}
|
||||
|
||||
zone.TomlRecords[index].Value = newValue
|
||||
}
|
||||
|
||||
zones = append(zones, zone)
|
||||
}
|
||||
|
||||
|
|
@ -77,5 +101,16 @@ func CreateTomlZone(zone TomlZone) error {
|
|||
return err
|
||||
}
|
||||
|
||||
for index, record := range zone.TomlRecords {
|
||||
if !strings.EqualFold(record.Type, "TXT") || len(record.Value) <= 255 {
|
||||
continue
|
||||
}
|
||||
|
||||
newValue := strings.ReplaceAll(record.Value, "\" \"", "")
|
||||
newValue = strings.ReplaceAll(newValue, "\"", "")
|
||||
|
||||
zone.TomlRecords[index].Value = newValue
|
||||
}
|
||||
|
||||
return toml.NewEncoder(file).Encode(&zone)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue