修订代码,示例;修复一个 toml多行字符串的bug

This commit is contained in:
e1732a364fed
2000-01-01 00:00:00 +00:00
parent bdcda5b930
commit 41db97b8cf
3 changed files with 8 additions and 4 deletions

View File

@@ -15,7 +15,8 @@ tag = "dial1"
host = "127.0.0.1"
port = 10801
uuid = "user:very\npass:simple"
#uuid = "user:very\npass:simple"
uuid = "user:admin\npass:nimda"
[[route]]
fromTag = ["my_socks5_1"]
@@ -34,8 +35,10 @@ user:admin
pass:nimda
"""
# 或者这种
#uuid = "user:very\npass:simple"
# 上面这个格式 根据toml的规范头部是没有 \n 的,但是尾部多了一个 \n, 不过不用担心,我们程序会修剪掉末尾的换行符.
# 或者这种,但是看起来不太美观
#uuid = "user:very\npass:simple"
users = [ {user = "very", pass = "simple"}, {user = "v2ray", pass = "hard"} ] #也可以用users 来存储多个用户

View File

@@ -57,7 +57,7 @@ func (ServerCreator) NewServer(lc *proxy.ListenConf) (proxy.Server, error) {
if userPass.InitWithStr(str) {
s.AddUser(&userPass)
} else {
if ce := utils.CanLogWarn("http: user and password format malformed. Will not use default uuid"); ce != nil {
if ce := utils.CanLogWarn("socks5: user and password format malformed. Will not use default uuid"); ce != nil {
ce.Write()
}
}

View File

@@ -158,6 +158,7 @@ func (ph *UserPass) InitWithUrl(u *url.URL) bool {
//uuid: "user:xxxx\npass:xxxx"
func (ph *UserPass) InitWithStr(str string) (ok bool) {
str = strings.TrimSuffix(str, "\n")
strs := strings.SplitN(str, "\n", 2)
if len(strs) != 2 {
return