-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (43 loc) · 1.44 KB
/
main.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
package main
import (
"context"
"database/sql"
"flag"
"github.com/google/subcommands"
"go.uber.org/zap"
"github.com/mmcloughlin/goperf/pkg/command"
// Register database drivers
_ "github.com/GoogleCloudPlatform/cloudsql-proxy/proxy/dialers/postgres" // cloudsqlpostgres
_ "github.com/lib/pq" // postgres
)
func main() {
command.Run(run)
}
// Top-level flags.
var (
driver = flag.String("driver", "postgres", "database driver")
conn = flag.String("conn", "", "database connection string")
)
func run(ctx context.Context, l *zap.Logger) int {
base := command.NewBase(l)
// Database commands.
subcommands.Register(NewMigrate(base), "database admin")
subcommands.Register(NewTruncate(base), "database admin")
subcommands.Register(NewCommits(base), "data ingestion")
subcommands.Register(NewRefs(base), "data ingestion")
subcommands.Register(NewPositions(base), "data ingestion")
subcommands.Register(NewAddMod(base), "data ingestion")
subcommands.Register(NewTraces(base), "data access")
subcommands.Register(NewChangeTest(base), "data access")
// Help.
subcommands.Register(subcommands.HelpCommand(), "help")
subcommands.Register(subcommands.CommandsCommand(), "help")
subcommands.Register(subcommands.FlagsCommand(), "help")
// Execute.
flag.Parse()
return int(subcommands.Execute(ctx))
}
// open database connection.
func open() (*sql.DB, error) {
return sql.Open(*driver, *conn)
}