-
Notifications
You must be signed in to change notification settings - Fork 5
/
meta.go
51 lines (45 loc) · 1.36 KB
/
meta.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package tab
import (
"database/sql"
"fmt"
"time"
_ "github.com/go-sql-driver/mysql"
)
type InfoC struct {
Physical_ip string
}
var (
k InfoC
)
func GetMetaClusterNameInfo(ClusterName string, MetaDsn string) error {
MessSelectSQL := fmt.Sprintf("select physical_ip from dbtool_dbinfo where cluster_name ='%v' ", ClusterName)
DB, err := sql.Open("mysql", MetaDsn)
if err != nil {
fmt.Printf("\x1b[%dm open: dbtool conn filed,err: %v \x1b[0m\n", 31, err)
}
defer DB.Close()
rows, err1 := DB.Query(MessSelectSQL)
if err1 != nil {
fmt.Printf("\x1b[%dm Query: dbtool_dbinfo not have %v \x1b[0m\n", 31, ClusterName)
}
if err3 := rows.Next(); err3 != true {
for rows.Next() {
err2 := rows.Scan(&k.Physical_ip)
if err2 != nil {
fmt.Printf("\x1b[%dm Check: dbtool_dbinfo --> %v none info exists \x1b[0m\n", 31, ClusterName)
fmt.Printf("\x1b[%dm Process Now Exit!!!! \x1b[0m\n", 31)
return err2
} else {
fmt.Printf("\x1b[%dm Check: dbtool_dbinfo --> %v exists \x1b[0m\n", 31, ClusterName)
}
}
} else {
fmt.Printf("\x1b[%dm Check: dbtool_dbinfo --> %v none info exists \x1b[0m\n", 31, ClusterName)
fmt.Printf("\x1b[%dm Process Now Exit!!!! \x1b[0m\n", 31)
return fmt.Errorf("Check: dbtool_dbinfo --> %v none info exists.", ClusterName)
}
DB.SetConnMaxLifetime(100 * time.Second)
DB.SetMaxOpenConns(2)
DB.SetMaxIdleConns(2)
return nil
}