55 lines
943 B
Go
55 lines
943 B
Go
package util
|
|
|
|
import (
|
|
"crypto/md5"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// GetAddress
|
|
// 获取监听地址
|
|
//
|
|
// @return []string
|
|
func GetListenAddress() []string {
|
|
address := Conf.Get("init", "addr")
|
|
addressArr := strings.Split(address, "://")
|
|
if addressArr[0] == "https" {
|
|
return []string{addressArr[0], addressArr[1]}
|
|
}
|
|
var addr string
|
|
if len(addressArr) > 1 {
|
|
addr = addressArr[1]
|
|
} else {
|
|
addr = addressArr[0]
|
|
}
|
|
return []string{"http", addr}
|
|
}
|
|
|
|
// GetProxy
|
|
// 获取代理服务器
|
|
//
|
|
// @return string
|
|
func GetProxyServer() string {
|
|
proxy := Conf.Get("proxy", "addr")
|
|
if proxy == "" {
|
|
return ""
|
|
}
|
|
proxyArr := strings.Split(proxy, "://")
|
|
if proxyArr[0] != "http" && proxyArr[0] != "https" {
|
|
return "http://" + proxyArr[0]
|
|
}
|
|
|
|
return proxy
|
|
}
|
|
|
|
// Md5
|
|
//
|
|
// @param text
|
|
// @return string
|
|
func Md5(text string) string {
|
|
hash := md5.New()
|
|
hash.Write([]byte(text))
|
|
byteData := hash.Sum(nil)
|
|
return fmt.Sprintf("%x", byteData)
|
|
}
|