2018-07-26 00:04:59 +08:00
|
|
|
package config
|
2018-06-10 22:50:03 +08:00
|
|
|
|
|
|
|
import (
|
2018-08-12 02:23:46 +08:00
|
|
|
"fmt"
|
2018-06-10 22:50:03 +08:00
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func trimArr(arr []string) (r []string) {
|
|
|
|
for _, e := range arr {
|
|
|
|
r = append(r, strings.Trim(e, " "))
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2018-08-12 02:23:46 +08:00
|
|
|
|
|
|
|
func genAddr(port int, allowLan bool) string {
|
|
|
|
if allowLan {
|
|
|
|
return fmt.Sprintf(":%d", port)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("127.0.0.1:%d", port)
|
|
|
|
}
|
2018-08-26 22:43:38 +08:00
|
|
|
|
|
|
|
func or(pointers ...*int) *int {
|
|
|
|
for _, p := range pointers {
|
|
|
|
if p != nil {
|
|
|
|
return p
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pointers[len(pointers)-1]
|
|
|
|
}
|
2018-09-08 19:53:24 +08:00
|
|
|
|
|
|
|
func parseOptions(startIdx int, params ...string) map[string]string {
|
|
|
|
mapping := make(map[string]string)
|
|
|
|
if len(params) <= startIdx {
|
|
|
|
return mapping
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, option := range params[startIdx:] {
|
|
|
|
pair := strings.SplitN(option, "=", 2)
|
|
|
|
if len(pair) != 2 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
mapping[strings.Trim(pair[0], " ")] = strings.Trim(pair[1], " ")
|
|
|
|
}
|
|
|
|
return mapping
|
|
|
|
}
|