mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 03:32:33 +08:00
Fixed: global mode and update log level
This commit is contained in:
parent
a1a58c31ae
commit
63c967b2b3
|
@ -94,6 +94,12 @@ func (c *Config) SetMode(mode Mode) {
|
||||||
c.event <- &Event{Type: "mode", Payload: mode}
|
c.event <- &Event{Type: "mode", Payload: mode}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetLogLevel change log level of clash
|
||||||
|
func (c *Config) SetLogLevel(level C.LogLevel) {
|
||||||
|
c.general.LogLevel = level
|
||||||
|
c.event <- &Event{Type: "log-level", Payload: level}
|
||||||
|
}
|
||||||
|
|
||||||
// General return clash general config
|
// General return clash general config
|
||||||
func (c *Config) General() General {
|
func (c *Config) General() General {
|
||||||
return *c.general
|
return *c.general
|
||||||
|
@ -225,6 +231,7 @@ func (c *Config) parseProxies(cfg *ini.File) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// init proxy
|
// init proxy
|
||||||
|
proxies["GLOBAL"], _ = adapters.NewSelector("GLOBAL", proxies)
|
||||||
proxies["DIRECT"] = adapters.NewDirect()
|
proxies["DIRECT"] = adapters.NewDirect()
|
||||||
proxies["REJECT"] = adapters.NewReject()
|
proxies["REJECT"] = adapters.NewReject()
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ type General struct {
|
||||||
AllowLan *bool `json:"allow-lan,omitempty"`
|
AllowLan *bool `json:"allow-lan,omitempty"`
|
||||||
Port *int `json:"port,omitempty"`
|
Port *int `json:"port,omitempty"`
|
||||||
SocksPort *int `json:"socks-port,omitempty"`
|
SocksPort *int `json:"socks-port,omitempty"`
|
||||||
|
LogLevel *string `json:"log-level,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
|
@ -50,7 +50,7 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// update errors
|
// update errors
|
||||||
var proxyErr, modeErr error
|
var proxyErr, modeErr, logLevelErr error
|
||||||
|
|
||||||
// update proxy
|
// update proxy
|
||||||
listener := proxy.Instance()
|
listener := proxy.Instance()
|
||||||
|
@ -70,9 +70,20 @@ func updateConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// update log-level
|
||||||
|
if general.LogLevel != nil {
|
||||||
|
level, ok := C.LogLevelMapping[*general.LogLevel]
|
||||||
|
if !ok {
|
||||||
|
logLevelErr = fmt.Errorf("Log Level error")
|
||||||
|
} else {
|
||||||
|
cfg.SetLogLevel(level)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hasError, errors := formatErrors(map[string]error{
|
hasError, errors := formatErrors(map[string]error{
|
||||||
"proxy": proxyErr,
|
"proxy": proxyErr,
|
||||||
"mode": modeErr,
|
"mode": modeErr,
|
||||||
|
"log-level": logLevelErr,
|
||||||
})
|
})
|
||||||
|
|
||||||
if hasError {
|
if hasError {
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
LocalAdapter "github.com/Dreamacro/clash/adapters/local"
|
LocalAdapter "github.com/Dreamacro/clash/adapters/local"
|
||||||
RemoteAdapter "github.com/Dreamacro/clash/adapters/remote"
|
|
||||||
cfg "github.com/Dreamacro/clash/config"
|
cfg "github.com/Dreamacro/clash/config"
|
||||||
C "github.com/Dreamacro/clash/constant"
|
C "github.com/Dreamacro/clash/constant"
|
||||||
"github.com/Dreamacro/clash/observable"
|
"github.com/Dreamacro/clash/observable"
|
||||||
|
@ -27,8 +26,7 @@ type Tunnel struct {
|
||||||
traffic *C.Traffic
|
traffic *C.Traffic
|
||||||
|
|
||||||
// Outbound Rule
|
// Outbound Rule
|
||||||
mode cfg.Mode
|
mode cfg.Mode
|
||||||
selector *RemoteAdapter.Selector
|
|
||||||
|
|
||||||
// Log
|
// Log
|
||||||
logCh chan interface{}
|
logCh chan interface{}
|
||||||
|
@ -93,7 +91,7 @@ func (t *Tunnel) handleConn(localConn C.ServerAdapter) {
|
||||||
case cfg.Direct:
|
case cfg.Direct:
|
||||||
proxy = t.proxies["DIRECT"]
|
proxy = t.proxies["DIRECT"]
|
||||||
case cfg.Global:
|
case cfg.Global:
|
||||||
proxy = t.selector
|
proxy = t.proxies["GLOBAL"]
|
||||||
// Rule
|
// Rule
|
||||||
default:
|
default:
|
||||||
proxy = t.match(addr)
|
proxy = t.match(addr)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user