Config option to set DNS resolver

This commit is contained in:
2025-04-23 20:56:27 +08:00
parent 9bd7ba6eb9
commit f1fe70386d
3 changed files with 15 additions and 1 deletions

12
main.go
View File

@@ -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)