|
@@ -13,6 +13,7 @@ import (
|
|
"image/png"
|
|
"image/png"
|
|
"math"
|
|
"math"
|
|
"math/rand"
|
|
"math/rand"
|
|
|
|
+ "net"
|
|
"os"
|
|
"os"
|
|
"os/exec"
|
|
"os/exec"
|
|
"regexp"
|
|
"regexp"
|
|
@@ -703,3 +704,24 @@ func FormatPrice(price float64) (str string) {
|
|
}
|
|
}
|
|
return strings.Join(arr, ".") //将一系列字符串连接为一个字符串,之间用sep来分隔。
|
|
return strings.Join(arr, ".") //将一系列字符串连接为一个字符串,之间用sep来分隔。
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+func GetLocalIP() (ip string, err error) {
|
|
|
|
+ addrs, err := net.InterfaceAddrs()
|
|
|
|
+ if err != nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ for _, addr := range addrs {
|
|
|
|
+ ipAddr, ok := addr.(*net.IPNet)
|
|
|
|
+ if !ok {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if ipAddr.IP.IsLoopback() {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ if !ipAddr.IP.IsGlobalUnicast() {
|
|
|
|
+ continue
|
|
|
|
+ }
|
|
|
|
+ return ipAddr.IP.String(), nil
|
|
|
|
+ }
|
|
|
|
+ return
|
|
|
|
+}
|