fix: make doh truly singleton

This commit is contained in:
ohaiibuzzle 2024-08-11 19:35:02 +07:00
parent c93ddd67e0
commit e9de332163

View File

@ -8,6 +8,7 @@ import (
"net"
"net/http"
"strings"
"sync"
"time"
"github.com/miekg/dns"
@ -20,8 +21,10 @@ type DoHClient struct {
}
var client *DoHClient
var clientOnce sync.Once
func GetDoHClient(upstream string) *DoHClient {
clientOnce.Do(func() {
if client == nil {
if !strings.HasPrefix(upstream, "https://") {
upstream = "https://" + upstream
@ -49,6 +52,7 @@ func GetDoHClient(upstream string) *DoHClient {
c: c,
}
}
})
return client
}