mirror of
https://github.com/coredns/coredns.git
synced 2025-11-01 10:43:17 -04:00
plugin/rewrite: use request.Request and other cleanups (#1920)
This was done anyway, but only deep in the functions, just do this everywhere; allows for shorter code and request.Request allows for caching as well. Cleanups, make it more Go like. * remove unneeded switches * remove testdir (why was this there??) * simplify the logic * remove unneeded variables * put short functions on a single line * fix documentation. * spin off wire funcs in wire.go, make them functions. Signed-off-by: Miek Gieben <miek@miek.nl>
This commit is contained in:
37
plugin/rewrite/wire.go
Normal file
37
plugin/rewrite/wire.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package rewrite
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// ipToWire writes IP address to wire/binary format, 4 or 16 bytes depends on IPV4 or IPV6.
|
||||
func ipToWire(family int, ipAddr string) ([]byte, error) {
|
||||
|
||||
switch family {
|
||||
case 1:
|
||||
return net.ParseIP(ipAddr).To4(), nil
|
||||
case 2:
|
||||
return net.ParseIP(ipAddr).To16(), nil
|
||||
}
|
||||
return nil, fmt.Errorf("invalid IP address family (i.e. version) %d", family)
|
||||
}
|
||||
|
||||
// uint16ToWire writes unit16 to wire/binary format
|
||||
func uint16ToWire(data uint16) []byte {
|
||||
buf := make([]byte, 2)
|
||||
binary.BigEndian.PutUint16(buf, uint16(data))
|
||||
return buf
|
||||
}
|
||||
|
||||
// portToWire writes port to wire/binary format, 2 bytes
|
||||
func portToWire(portStr string) ([]byte, error) {
|
||||
|
||||
port, err := strconv.ParseUint(portStr, 10, 16)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return uint16ToWire(uint16(port)), nil
|
||||
}
|
||||
Reference in New Issue
Block a user