add service

This commit is contained in:
notch
2020-12-21 14:55:30 +08:00
parent 7094607698
commit c108963b65
14 changed files with 1481 additions and 13 deletions

View File

@@ -8,6 +8,7 @@ import (
"fmt"
"net"
"strings"
"github.com/emitter-io/address"
)
@@ -18,6 +19,21 @@ func GetIP(addr net.Addr) string {
return s[:i]
}
// GetLocalIP 获取本地IP
func GetLocalIP() []string {
addrs, _ := net.InterfaceAddrs()
ips := []string{}
for _, address := range addrs {
// 检查ip地址判断是否回环地址
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ips = append(ips, ipnet.IP.String())
}
}
}
return ips
}
// IsLocalhostIP 判断是否为本机IP
func IsLocalhostIP(ip net.IP) bool {
for _, localhost := range loopbackBlocks {