mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-11-16 19:56:51 +08:00
4a0413a33d
findProcess slow down connection due to repeat call to FindProcessName in router environment this option has 3 values: always, strict, off - always, equal to enable-process: true. Just try to merge all process related option into one - strict, as default value, behavior remains unchanged - off, turn off findProcess, useful in router environment
58 lines
1012 B
Go
58 lines
1012 B
Go
package process
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
FindProcessAlways = "always"
|
|
FindProcessStrict = "strict"
|
|
FindProcessOff = "off"
|
|
)
|
|
|
|
var (
|
|
validModes = map[string]struct{}{
|
|
FindProcessAlways: {},
|
|
FindProcessOff: {},
|
|
FindProcessStrict: {},
|
|
}
|
|
)
|
|
|
|
type FindProcessMode string
|
|
|
|
func (m FindProcessMode) Always() bool {
|
|
return m == FindProcessAlways
|
|
}
|
|
|
|
func (m FindProcessMode) Off() bool {
|
|
return m == FindProcessOff
|
|
}
|
|
|
|
func (m *FindProcessMode) UnmarshalYAML(unmarshal func(any) error) error {
|
|
var tp string
|
|
if err := unmarshal(&tp); err != nil {
|
|
return err
|
|
}
|
|
return m.Set(tp)
|
|
}
|
|
|
|
func (m *FindProcessMode) UnmarshalJSON(data []byte) error {
|
|
var tp string
|
|
if err := json.Unmarshal(data, &tp); err != nil {
|
|
return err
|
|
}
|
|
return m.Set(tp)
|
|
}
|
|
|
|
func (m *FindProcessMode) Set(value string) error {
|
|
mode := strings.ToLower(value)
|
|
_, exist := validModes[mode]
|
|
if !exist {
|
|
return errors.New("invalid find process mode")
|
|
}
|
|
*m = FindProcessMode(mode)
|
|
return nil
|
|
}
|