Config option to set DNS resolver
This commit is contained in:
parent
9bd7ba6eb9
commit
f1fe70386d
@ -1,4 +1,5 @@
|
||||
{
|
||||
"ListenAddress": "127.0.0.1:3128",
|
||||
"ListenType": "tcp4"
|
||||
"ListenType": "tcp4",
|
||||
"DNSResolver": "192.168.1.1:53"
|
||||
}
|
||||
|
@ -4,4 +4,5 @@ type Config struct {
|
||||
ListenAddress string // Address to listen on, passed to net.Listen
|
||||
ListenType string // Type of network to listen on, passed to net.Listen. One of tcp, tcp4 and tcp6
|
||||
|
||||
DNSResolver string // Address to send UDP & TCP DNS requests to. If set, the Go resolver will also be forced.
|
||||
}
|
||||
|
12
main.go
12
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
@ -8,6 +9,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"edgaru089.ink/go/regolith/internal/conf"
|
||||
"edgaru089.ink/go/regolith/internal/http"
|
||||
@ -44,6 +46,16 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
if len(conf.DNSResolver) != 0 {
|
||||
dialer := &net.Dialer{
|
||||
Timeout: time.Second * 10,
|
||||
}
|
||||
net.DefaultResolver.PreferGo = true
|
||||
net.DefaultResolver.Dial = func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||
return dialer.Dial(network, conf.DNSResolver)
|
||||
}
|
||||
}
|
||||
|
||||
listener, err := net.Listen(conf.ListenType, conf.ListenAddress)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
Loading…
x
Reference in New Issue
Block a user