mirror of
https://github.com/e1732a364fed/v2ray_simple.git
synced 2026-04-23 01:37:05 +08:00
修订代码
This commit is contained in:
+2
-4
@@ -112,7 +112,7 @@ func (m *M) LoadConfigByTomlBytes(bs []byte) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
// 先检查configFileName是否存在,存在就尝试加载文件到 standardConf , 否则尝试通过 listenURL, dialURL 参数 创建simpleConf
|
||||
// 先检查configFileName是否存在,存在就尝试加载文件到 standardConf , 否则尝试通过 listenURL, dialURL 参数 创建urlConf
|
||||
func (m *M) LoadConfig(configFileName, listenURL, dialURL string) (confMode int, err error) {
|
||||
|
||||
fpath := utils.GetFilePath(configFileName)
|
||||
@@ -135,8 +135,6 @@ func (m *M) LoadConfig(configFileName, listenURL, dialURL string) (confMode int,
|
||||
}
|
||||
|
||||
} else {
|
||||
// confMode = proxy.SimpleMode
|
||||
// m.simpleConf, m.RoutingEnv.Fallback, err = proxy.LoadSimpleConf_byFile(fpath)
|
||||
return -1, errors.New("file passed in but no .toml suffix")
|
||||
}
|
||||
|
||||
@@ -148,7 +146,7 @@ url:
|
||||
log.Printf("trying listenURL and dialURL \n")
|
||||
|
||||
confMode = proxy.UrlMode
|
||||
m.simpleConf, err = proxy.LoadUrlConf(listenURL, dialURL)
|
||||
m.urlConf, err = proxy.LoadUrlConf(listenURL, dialURL)
|
||||
} else {
|
||||
|
||||
log.Println(proxy.ErrStrNoListenUrl)
|
||||
|
||||
+2
-2
@@ -112,12 +112,12 @@ func (m *M) HotDeleteServer(index int) {
|
||||
|
||||
func (m *M) LoadSimpleConf(hot bool) (result int) {
|
||||
var ser proxy.Server
|
||||
result, ser = m.loadSimpleServer(m.simpleConf)
|
||||
result, ser = m.loadSimpleServer(m.urlConf)
|
||||
if result < 0 {
|
||||
return
|
||||
}
|
||||
var cli proxy.Client
|
||||
result, cli = m.loadSimpleClient(m.simpleConf)
|
||||
result, cli = m.loadSimpleClient(m.urlConf)
|
||||
if result < 0 {
|
||||
return
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ type M struct {
|
||||
ApiServerConf
|
||||
|
||||
standardConf proxy.StandardConf
|
||||
simpleConf proxy.UrlConf
|
||||
urlConf proxy.UrlConf
|
||||
appConf *AppConf
|
||||
|
||||
v2ray_simple.GlobalInfo
|
||||
|
||||
+3
-70
@@ -8,77 +8,10 @@ import (
|
||||
type UrlConf struct {
|
||||
ListenUrl string `json:"listen"`
|
||||
DialUrl string `json:"dial"`
|
||||
//Route []*netLayer.RuleConf `json:"route"`
|
||||
//Fallbacks []*httpLayer.FallbackConf `json:"fallbacks"`
|
||||
//MyCountryISO_3166 string `json:"mycountry"`
|
||||
}
|
||||
|
||||
// load simpleConf
|
||||
/*
|
||||
func LoadSimpleConfigFile(fileNamePath string) (config UrlConf, err error) {
|
||||
|
||||
var cf *os.File
|
||||
if cf, err = os.Open(fileNamePath); err == nil {
|
||||
defer cf.Close()
|
||||
bs, _ := io.ReadAll(cf)
|
||||
if err = json.Unmarshal(bs, &config); err != nil {
|
||||
err = utils.ErrInErr{
|
||||
ErrDesc: "can not parse config file ",
|
||||
ErrDetail: err,
|
||||
Data: fileNamePath,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return
|
||||
} else {
|
||||
err = utils.ErrInErr{ErrDesc: "can't open config file", ErrDetail: err}
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// load simpleConf
|
||||
func LoadSimpleConfigFromStr(str string) (config UrlConf, hasE bool, E utils.ErrInErr) {
|
||||
|
||||
if err := json.Unmarshal([]byte(str), &config); err != nil {
|
||||
E = utils.ErrInErr{ErrDesc: "can not parse config ", ErrDetail: err}
|
||||
hasE = true
|
||||
}
|
||||
return
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// load simpleConf and fallbacks
|
||||
func LoadSimpleConf_byFile(fpath string) (simpleConf SimpleConf, err error) {
|
||||
//默认认为所有其他后缀的都是json格式,因为有时会用 server.json.vless 这种写法
|
||||
// 默认所有json格式的文件都为 极简模式
|
||||
|
||||
simpleConf, err = LoadSimpleConfigFile(fpath)
|
||||
if err != nil {
|
||||
|
||||
log.Printf("can not load simple config file: %s\n", err.Error())
|
||||
return
|
||||
} else {
|
||||
err = nil
|
||||
}
|
||||
// if simpleConf.Fallbacks != nil {
|
||||
// mainFallback = httpLayer.NewClassicFallbackFromConfList(simpleConf.Fallbacks)
|
||||
// }
|
||||
|
||||
if simpleConf.DialUrl == "" {
|
||||
|
||||
simpleConf.DialUrl = DirectURL
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
// listenURL 不可为空。dialURL如果为空,会自动被设为 DirectURL
|
||||
func LoadUrlConf(listenURL, dialURL string) (simpleConf UrlConf, err error) {
|
||||
func LoadUrlConf(listenURL, dialURL string) (urlConf UrlConf, err error) {
|
||||
|
||||
if dialURL == "" {
|
||||
dialURL = DirectURL
|
||||
@@ -90,7 +23,7 @@ func LoadUrlConf(listenURL, dialURL string) (simpleConf UrlConf, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
simpleConf = UrlConf{
|
||||
urlConf = UrlConf{
|
||||
ListenUrl: listenURL,
|
||||
}
|
||||
|
||||
@@ -100,7 +33,7 @@ func LoadUrlConf(listenURL, dialURL string) (simpleConf UrlConf, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
simpleConf.DialUrl = dialURL
|
||||
urlConf.DialUrl = dialURL
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user