Propagate DNS setting to configuration

This commit is contained in:
9seconds
2026-02-27 16:23:24 +01:00
parent 317d7380cb
commit 897e6bf505
6 changed files with 234 additions and 14 deletions
+12
View File
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"net"
"net/url"
"github.com/9seconds/mtg/v2/mtglib"
)
@@ -56,6 +57,7 @@ type Config struct {
Idle TypeDuration `json:"idle"`
} `json:"timeout"`
DOHIP TypeIP `json:"dohIp"`
DNS TypeDNSURI `json:"dns"`
Proxies []TypeProxyURL `json:"proxies"`
} `json:"network"`
Stats struct {
@@ -76,6 +78,16 @@ type Config struct {
} `json:"stats"`
}
func (c *Config) GetDNS() *url.URL {
var dohURL *url.URL
if dohIP := c.Network.DOHIP.Get(nil); dohIP != nil {
dohURL, _ = url.Parse("https://" + dohIP.String())
}
return c.Network.DNS.Get(dohURL)
}
func (c *Config) GetDomainFrontingPort(defaultValue uint) uint {
if port := c.DomainFronting.Port.Get(0); port != 0 {
return port