fix: api does not return configuration value

This commit is contained in:
xishang0128 2024-02-21 17:14:08 +08:00
parent 9e7eaf720f
commit 1c7e011f87
No known key found for this signature in database
GPG Key ID: 44A1E10B5ADF68CB
3 changed files with 46 additions and 12 deletions

View File

@ -3,19 +3,37 @@ package geodata
import ( import (
"errors" "errors"
"fmt" "fmt"
"golang.org/x/sync/singleflight"
"strings" "strings"
"golang.org/x/sync/singleflight"
"github.com/metacubex/mihomo/component/geodata/router" "github.com/metacubex/mihomo/component/geodata/router"
C "github.com/metacubex/mihomo/constant" C "github.com/metacubex/mihomo/constant"
"github.com/metacubex/mihomo/log" "github.com/metacubex/mihomo/log"
) )
var geoLoaderName = "memconservative" var (
var geoSiteMatcher = "succinct" geoMode bool
AutoUpdate bool
UpdateInterval int
geoLoaderName = "memconservative"
geoSiteMatcher = "succinct"
)
// geoLoaderName = "standard" // geoLoaderName = "standard"
func GeodataMode() bool {
return geoMode
}
func GeoAutoUpdate() bool {
return AutoUpdate
}
func GeoUpdateInterval() int {
return UpdateInterval
}
func LoaderName() string { func LoaderName() string {
return geoLoaderName return geoLoaderName
} }
@ -24,6 +42,16 @@ func SiteMatcherName() string {
return geoSiteMatcher return geoSiteMatcher
} }
func SetGeodataMode(newGeodataMode bool) {
geoMode = newGeodataMode
}
func SetGeoAutoUpdate(newAutoUpdate bool) {
AutoUpdate = newAutoUpdate
}
func SetGeoUpdateInterval(newGeoUpdateInterval int) {
UpdateInterval = newGeoUpdateInterval
}
func SetLoader(newLoader string) { func SetLoader(newLoader string) {
if newLoader == "memc" { if newLoader == "memc" {
newLoader = "memconservative" newLoader = "memconservative"

View File

@ -607,6 +607,9 @@ func ParseRawConfig(rawCfg *RawConfig) (*Config, error) {
} }
func parseGeneral(cfg *RawConfig) (*General, error) { func parseGeneral(cfg *RawConfig) (*General, error) {
geodata.SetGeodataMode(cfg.GeodataMode)
geodata.SetGeoAutoUpdate(cfg.GeoAutoUpdate)
geodata.SetGeoUpdateInterval(cfg.GeoUpdateInterval)
geodata.SetLoader(cfg.GeodataLoader) geodata.SetLoader(cfg.GeodataLoader)
geodata.SetSiteMatcher(cfg.GeositeMatcher) geodata.SetSiteMatcher(cfg.GeositeMatcher)
C.GeoAutoUpdate = cfg.GeoAutoUpdate C.GeoAutoUpdate = cfg.GeoAutoUpdate

View File

@ -146,15 +146,18 @@ func GetGeneral() *config.General {
AllowLan: listener.AllowLan(), AllowLan: listener.AllowLan(),
BindAddress: listener.BindAddress(), BindAddress: listener.BindAddress(),
}, },
Controller: config.Controller{}, Controller: config.Controller{},
Mode: tunnel.Mode(), Mode: tunnel.Mode(),
LogLevel: log.Level(), LogLevel: log.Level(),
IPv6: !resolver.DisableIPv6, IPv6: !resolver.DisableIPv6,
GeodataLoader: G.LoaderName(), GeodataMode: G.GeodataMode(),
GeositeMatcher: G.SiteMatcherName(), GeoAutoUpdate: G.GeoAutoUpdate(),
Interface: dialer.DefaultInterface.Load(), GeoUpdateInterval: G.GeoUpdateInterval(),
Sniffing: tunnel.IsSniffing(), GeodataLoader: G.LoaderName(),
TCPConcurrent: dialer.GetTcpConcurrent(), GeositeMatcher: G.SiteMatcherName(),
Interface: dialer.DefaultInterface.Load(),
Sniffing: tunnel.IsSniffing(),
TCPConcurrent: dialer.GetTcpConcurrent(),
} }
return general return general