fix concurrent issue in buffer handling of package grand

This commit is contained in:
john
2020-05-17 12:46:28 +08:00
parent 3559436d1e
commit 351de5ee6a
2 changed files with 7 additions and 41 deletions

View File

@ -2,47 +2,11 @@ package main
import (
"fmt"
"net"
)
func getMacAddrs() (macAddrs []string) {
netInterfaces, err := net.Interfaces()
if err != nil {
fmt.Printf("fail to get net interfaces: %v", err)
return macAddrs
}
for _, netInterface := range netInterfaces {
macAddr := netInterface.HardwareAddr.String()
if len(macAddr) == 0 {
continue
}
macAddrs = append(macAddrs, macAddr)
}
return macAddrs
}
func getIPs() (ips []string) {
interfaceAddr, err := net.InterfaceAddrs()
if err != nil {
fmt.Printf("fail to get net interface addrs: %v", err)
return ips
}
for _, address := range interfaceAddr {
ipNet, isValidIpNet := address.(*net.IPNet)
if isValidIpNet && !ipNet.IP.IsLoopback() {
if ipNet.IP.To4() != nil {
ips = append(ips, ipNet.IP.String())
}
}
}
return ips
}
func main() {
fmt.Printf("mac addrs: %q\n", getMacAddrs())
fmt.Printf("ips: %q\n", getIPs())
b1 := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 0}
b2 := b1[:2]
b1[0] = 9
fmt.Println(b2)
}