cover more in util

This commit is contained in:
yedf2 2021-07-29 23:23:59 +08:00
parent 30e0628951
commit ad4f0b5fac
2 changed files with 6 additions and 13 deletions

View File

@ -62,13 +62,9 @@ func GenGid() string {
func getOneHexIP() string { func getOneHexIP() string {
addrs, err := net.InterfaceAddrs() addrs, err := net.InterfaceAddrs()
if err != nil { if err == nil {
fmt.Printf("cannot get ip, default to another call") for _, address := range addrs {
return gNode.Generate().Base58() if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() && ipnet.IP.To4() != nil {
}
for _, address := range addrs {
if ipnet, ok := address.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
if ipnet.IP.To4() != nil {
ip := ipnet.IP.To4().String() ip := ipnet.IP.To4().String()
ns := strings.Split(ip, ".") ns := strings.Split(ip, ".")
r := []byte{} r := []byte{}
@ -77,9 +73,8 @@ func getOneHexIP() string {
} }
return hex.EncodeToString(r) return hex.EncodeToString(r)
} }
} }
} }
fmt.Printf("none ipv4, default to another call") fmt.Printf("err is: %s", err.Error())
return gNode.Generate().Base58() return "" // 获取不到IP则直接返回空
} }

View File

@ -16,9 +16,7 @@ func RunSQLScript(mysql map[string]string, script string, skipDrop bool) {
db, con := common.DbAlone(conf) db, con := common.DbAlone(conf)
defer func() { con.Close() }() defer func() { con.Close() }()
content, err := ioutil.ReadFile(script) content, err := ioutil.ReadFile(script)
if err != nil { e2p(err)
e2p(err)
}
sqls := strings.Split(string(content), ";") sqls := strings.Split(string(content), ";")
for _, sql := range sqls { for _, sql := range sqls {
s := strings.TrimSpace(sql) s := strings.TrimSpace(sql)