我正在尝试运行我在网上找到的示例 Go 程序,如下所示:
/* IP */
package main
import (
"net"
"os"
"fmt"
)
func main() {
if len(os.Args) != 2 {
fmt.Fprintf(os.Stderr, "Usage: %s ip-addr\n", os.Args[0])
os.Exit(1)
}
name := os.Args[1]
addr := net.ParseIP(name)
if addr == nil {
fmt.Println("Invalid address")
} else {
fmt.Println("The address is ", addr.String())
}
os.Exit(0)
}
然后我尝试使用以下方法编译它:
6g ip.go
我收到以下错误:
ip.go:7: can't find import: net
我的go版本没有net包吗?还是我使用了错误版本的编译器?谢谢!