refactor(panel): drop two duplicated helpers

SettingService.GetDefaultJSONConfig was a byte-identical copy of
GetDefaultXrayConfig with no callers anywhere in the tree.

amneziawgnet.normalizeDNSServer re-implemented the exported
amneziawg.NormalizeDNSServer line for line, in a file that already imports
that package for EffectiveMTU three lines above it. Its two callers now use
the exported one, so the bare-IP-to-host:port rule has a single definition.
This commit is contained in:
Sanaei
2026-09-10 21:08:13 +02:00
parent 0fbdf0f9bf
commit 3f1e52f09e
4 changed files with 4 additions and 27 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
)
@@ -78,7 +79,7 @@ func dnsCacheKey(tag, dnsServer, host string) string {
}
func resolveTunnelVia(ctx context.Context, dev *Device, tag string, dnsServer string, host string) (netip.Addr, error) {
normDNS := normalizeDNSServer(dnsServer)
normDNS := amneziawg.NormalizeDNSServer(dnsServer)
if normDNS == "" {
normDNS = defaultDNSFor(dev.LocalAddresses())
}
+2 -1
View File
@@ -14,6 +14,7 @@ import (
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/adapters/gonet"
"github.com/mhsanaei/3x-ui/v3/internal/amneziawg"
"github.com/mhsanaei/3x-ui/v3/internal/logger"
)
@@ -77,7 +78,7 @@ func (s *socks5EgressServer) SetDNSServer(addr string) {
func (s *socks5EgressServer) SetStack(tag string, dev *Device, dnsServer ...string) {
norm := ""
if len(dnsServer) > 0 && dnsServer[0] != "" {
norm = normalizeDNSServer(dnsServer[0])
norm = amneziawg.NormalizeDNSServer(dnsServer[0])
}
s.mu.Lock()
prevDev := s.stacks[tag]
-16
View File
@@ -2,7 +2,6 @@ package amneziawgnet
import (
"fmt"
"net/netip"
"strings"
"sync"
@@ -53,21 +52,6 @@ func outboundFingerprint(inst amneziawg.OutboundInstance) string {
strings.Join(inst.Address, ","))
}
// normalizeDNSServer normalizes a configured DNS server to host:port.
func normalizeDNSServer(s string) string {
s = strings.TrimSpace(s)
if s == "" {
return ""
}
if addr, err := netip.ParseAddr(s); err == nil {
return netip.AddrPortFrom(addr, 53).String()
}
if ap, err := netip.ParseAddrPort(s); err == nil {
return ap.String()
}
return s
}
// Reconcile converges devices to desired and stops removed tags; per-tick
// contract of Manager.Reconcile -- errors log, never abort the batch.
func (m *OutboundManager) Reconcile(desired []OutboundDesired) {
-9
View File
@@ -209,15 +209,6 @@ var defaultValueMap = map[string]string{
// It handles configuration storage, retrieval, and validation for all system settings.
type SettingService struct{}
func (s *SettingService) GetDefaultJSONConfig() (any, error) {
var jsonData any
err := json.Unmarshal([]byte(xrayTemplateConfig), &jsonData)
if err != nil {
return nil, err
}
return jsonData, nil
}
func (s *SettingService) GetAllSetting() (*entity.AllSetting, error) {
db := database.GetDB()
settings := make([]*model.Setting, 0)