-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (38 loc) · 1.14 KB
/
main.go
File metadata and controls
50 lines (38 loc) · 1.14 KB
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
package main
import (
"fmt"
"github.com/daniel-cole/mysql-rowcount/config"
"github.com/daniel-cole/mysql-rowcount/db"
"github.com/daniel-cole/mysql-rowcount/row_count"
"github.com/daniel-cole/mysql-rowcount/util"
"github.com/go-sql-driver/mysql"
"log"
"os"
)
var version = "undefined"
var rowCountConfig *config.RowCountConfig
func main() {
var arg string
if len(os.Args) > 1 {
arg = os.Args[1]
}
if arg == "version" {
fmt.Println(version)
os.Exit(0)
}
rowCountConfig = config.LoadConfig()
if util.CheckFileExists(rowCountConfig.OutputFile) {
log.Fatalf("Output file already exists: %s", rowCountConfig.OutputFile)
}
db.Setup(&mysql.Config{
User: rowCountConfig.User,
Passwd: rowCountConfig.Passwd,
Addr: rowCountConfig.Addr,
Net: rowCountConfig.Net,
AllowNativePasswords: rowCountConfig.AllowNativePasswords,
})
defer db.DB.Close()
for _, tableRowCount := range row_count.FetchDatabaseTableRowCount(rowCountConfig) {
util.WriteBytesToFile(rowCountConfig.OutputFile, []byte(fmt.Sprintf("%s %d\n", tableRowCount.Table, tableRowCount.RowCount)))
}
}