mirror of
https://github.com/xvzc/SpoofDPI.git
synced 2025-01-04 13:24:46 +00:00
fix: make doh truly singleton
This commit is contained in:
parent
c93ddd67e0
commit
e9de332163
@ -8,6 +8,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
@ -20,8 +21,10 @@ type DoHClient struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var client *DoHClient
|
var client *DoHClient
|
||||||
|
var clientOnce sync.Once
|
||||||
|
|
||||||
func GetDoHClient(upstream string) *DoHClient {
|
func GetDoHClient(upstream string) *DoHClient {
|
||||||
|
clientOnce.Do(func() {
|
||||||
if client == nil {
|
if client == nil {
|
||||||
if !strings.HasPrefix(upstream, "https://") {
|
if !strings.HasPrefix(upstream, "https://") {
|
||||||
upstream = "https://" + upstream
|
upstream = "https://" + upstream
|
||||||
@ -49,6 +52,7 @@ func GetDoHClient(upstream string) *DoHClient {
|
|||||||
c: c,
|
c: c,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user