Browse Source

cover more in util

pull/13/head
yedf2 5 years ago
parent
commit
ad4f0b5fac
  1. 15
      dtmsvr/utils.go
  2. 4
      examples/data.go

15
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,则直接返回空
}

4
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)

Loading…
Cancel
Save