From a87825466271753d7aef8f56c6b5ef77ca5027b2 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Wed, 17 Apr 2024 10:08:54 +0800 Subject: [PATCH] feat: support `-ext-ctl-unix` cmdline to override external controller unix address --- hub/hub.go | 6 ++++++ main.go | 25 +++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/hub/hub.go b/hub/hub.go index 6d5bf49f..38779e13 100644 --- a/hub/hub.go +++ b/hub/hub.go @@ -21,6 +21,12 @@ func WithExternalController(externalController string) Option { } } +func WithExternalControllerUnix(externalControllerUnix string) Option { + return func(cfg *config.Config) { + cfg.General.ExternalControllerUnix = externalControllerUnix + } +} + func WithSecret(secret string) Option { return func(cfg *config.Config) { cfg.General.Secret = secret diff --git a/main.go b/main.go index 748fa2e3..afe9cfd2 100644 --- a/main.go +++ b/main.go @@ -23,16 +23,17 @@ import ( ) var ( - version bool - testConfig bool - geodataMode bool - homeDir string - configFile string - externalUI string - externalController string - secret string - updateGeoMux sync.Mutex - updatingGeo = false + version bool + testConfig bool + geodataMode bool + homeDir string + configFile string + externalUI string + externalController string + externalControllerUnix string + secret string + updateGeoMux sync.Mutex + updatingGeo = false ) func init() { @@ -40,6 +41,7 @@ func init() { flag.StringVar(&configFile, "f", os.Getenv("CLASH_CONFIG_FILE"), "specify configuration file") flag.StringVar(&externalUI, "ext-ui", os.Getenv("CLASH_OVERRIDE_EXTERNAL_UI_DIR"), "override external ui directory") flag.StringVar(&externalController, "ext-ctl", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER"), "override external controller address") + flag.StringVar(&externalControllerUnix, "ext-ctl-unix", os.Getenv("CLASH_OVERRIDE_EXTERNAL_CONTROLLER_UNIX"), "override external controller unix address") flag.StringVar(&secret, "secret", os.Getenv("CLASH_OVERRIDE_SECRET"), "override secret for RESTful API") flag.BoolVar(&geodataMode, "m", false, "set geodata mode") flag.BoolVar(&version, "v", false, "show current version of mihomo") @@ -102,6 +104,9 @@ func main() { if externalController != "" { options = append(options, hub.WithExternalController(externalController)) } + if externalControllerUnix != "" { + options = append(options, hub.WithExternalControllerUnix(externalControllerUnix)) + } if secret != "" { options = append(options, hub.WithSecret(secret)) }