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:
29
models/util.go
Normal file
29
models/util.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/gob"
|
||||
"strconv"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func copyObj(input interface{}, output interface{}) error {
|
||||
buf := &bytes.Buffer{}
|
||||
enc := gob.NewEncoder(buf)
|
||||
dec := gob.NewDecoder(buf)
|
||||
if err := enc.Encode(input); err != nil {
|
||||
return err
|
||||
}
|
||||
return dec.Decode(output)
|
||||
}
|
||||
|
||||
// atou32 converts a string to uint32 or panics.
|
||||
// DEPRECATED: This will go away when SOA record handling is rewritten.
|
||||
func atou32(s string) uint32 {
|
||||
i64, err := strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
panic(errors.Errorf("atou32 failed (%v) (err=%v", s, err))
|
||||
}
|
||||
return uint32(i64)
|
||||
}
|
||||
Reference in New Issue
Block a user