forked from burningalchemist/sql_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drivers_gen.go
69 lines (58 loc) · 1.29 KB
/
drivers_gen.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//go:build ignore
package main
import (
"fmt"
"os"
. "github.com/dave/jennifer/jen"
)
const (
packageName string = "sql_exporter"
filename string = "drivers.go"
)
var driverList = map[string][]string{
"minimal": {
"github.com/go-sql-driver/mysql",
"github.com/lib/pq",
"github.com/microsoft/go-mssqldb/azuread",
},
"extra": {
"github.com/ClickHouse/clickhouse-go/v2",
"github.com/jackc/pgx/v5/stdlib",
"github.com/snowflakedb/gosnowflake",
"github.com/vertica/vertica-sql-go",
"github.com/sijms/go-ora/v2",
},
"custom": {
"github.com/mithrandie/csvq-driver",
},
}
func main() {
var enabledDrivers []string
args := os.Args[2:]
if args[0] == "all" {
for k := range driverList {
if k != "custom" {
enabledDrivers = append(enabledDrivers, driverList[k]...)
}
}
} else {
var ok bool
enabledDrivers, ok = driverList[args[0]]
if !ok {
fmt.Printf("Nonexistent key. Do nothing.\n")
os.Exit(0)
}
}
f := NewFile(packageName)
f.HeaderComment("// Code generated by \"drivers_gen.go\"")
f.Anon(enabledDrivers...)
fmt.Println("Following drivers are to be added:")
for _, v := range enabledDrivers {
fmt.Printf("> %s\n", v)
}
fmt.Printf("Save to '%s'\n", filename)
if err := f.Save(filename); err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}