client: add start params

Proxy names specified in 'start' params divided by ',' will be started.
If it is empty or not defined, all proxies will be started.
This commit is contained in:
fatedier
2017-05-25 01:45:38 +08:00
parent 150682ec63
commit 49b503c17b
5 changed files with 31 additions and 9 deletions

View File

@@ -18,6 +18,7 @@ import (
"fmt"
"os"
"strconv"
"strings"
ini "github.com/vaughan0/go-ini"
)
@@ -39,6 +40,7 @@ type ClientCommonConf struct {
TcpMux bool
User string
LoginFailExit bool
Start map[string]struct{}
HeartBeatInterval int64
HeartBeatTimeout int64
}
@@ -58,6 +60,7 @@ func GetDeaultClientCommonConf() *ClientCommonConf {
TcpMux: true,
User: "",
LoginFailExit: true,
Start: make(map[string]struct{}),
HeartBeatInterval: 30,
HeartBeatTimeout: 90,
}
@@ -136,6 +139,14 @@ func LoadClientCommonConf(conf ini.File) (cfg *ClientCommonConf, err error) {
cfg.User = tmpStr
}
tmpStr, ok = conf.Get("common", "start")
if ok {
proxyNames := strings.Split(tmpStr, ",")
for _, name := range proxyNames {
cfg.Start[name] = struct{}{}
}
}
tmpStr, ok = conf.Get("common", "login_fail_exit")
if ok && tmpStr == "false" {
cfg.LoginFailExit = false

View File

@@ -466,14 +466,21 @@ func (cfg *HttpsProxyConf) Check() (err error) {
return
}
func LoadProxyConfFromFile(conf ini.File) (proxyConfs map[string]ProxyConf, err error) {
var prefix string
if ClientCommonCfg.User != "" {
prefix = ClientCommonCfg.User + "."
// if len(startProxy) is 0, start all
// otherwise just start proxies in startProxy map
func LoadProxyConfFromFile(prefix string, conf ini.File, startProxy map[string]struct{}) (proxyConfs map[string]ProxyConf, err error) {
if prefix != "" {
prefix += "."
}
startAll := true
if len(startProxy) > 0 {
startAll = false
}
proxyConfs = make(map[string]ProxyConf)
for name, section := range conf {
if name != "common" {
_, shouldStart := startProxy[name]
if name != "common" && (startAll || shouldStart) {
cfg, err := NewProxyConfFromFile(name, section)
if err != nil {
return proxyConfs, err