From ad4f0b5fac17f4f73306b9539baf42a3a331860a Mon Sep 17 00:00:00 2001 From: yedf2 <120050102@qq.com> Date: Thu, 29 Jul 2021 23:23:59 +0800 Subject: [PATCH] cover more in util --- dtmsvr/utils.go | 15 +++++---------- examples/data.go | 4 +--- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/dtmsvr/utils.go b/dtmsvr/utils.go index ad87dcd..63b20ea 100644 --- a/dtmsvr/utils.go +++ b/dtmsvr/utils.go @@ -62,13 +62,9 @@ func GenGid() string { func getOneHexIP() string { addrs, err := net.InterfaceAddrs() - if err != nil { - fmt.Printf("cannot get ip, default to another call") - return gNode.Generate().Base58() - } - for _, address := range addrs { - if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() { - if ipnet.IP.To4() != nil { + if err == nil { + for _, address := range addrs { + if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil { ip := ipnet.IP.To4().String() ns := strings.Split(ip, ".") r := []byte{} @@ -77,9 +73,8 @@ func getOneHexIP() string { } return hex.EncodeToString(r) } - } } - fmt.Printf("none ipv4, default to another call") - return gNode.Generate().Base58() + fmt.Printf("err is: %s", err.Error()) + return "" // 获取不到IP,则直接返回空 } diff --git a/examples/data.go b/examples/data.go index d9806a2..e7dcda6 100644 --- a/examples/data.go +++ b/examples/data.go @@ -16,9 +16,7 @@ func RunSQLScript(mysql map[string]string, script string, skipDrop bool) { db, con := common.DbAlone(conf) defer func() { con.Close() }() content, err := ioutil.ReadFile(script) - if err != nil { - e2p(err) - } + e2p(err) sqls := strings.Split(string(content), ";") for _, sql := range sqls { s := strings.TrimSpace(sql)