-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 941 Bytes
/
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
package main
import (
"fmt"
"os"
"github.com/kzaag/dp/cmn"
"github.com/kzaag/dp/pgsql"
"github.com/kzaag/dp/target"
_ "github.com/lib/pq"
)
func main() {
var c *target.Config
var err error
/* read user parameters */
args := target.NewArgsFromCli()
/*
parse configuration file
*/
if c, err = target.NewConfigFromPath(args.ConfigPath, args); err != nil {
cmn.CndPrintError(args.Raw, err)
os.Exit(2)
}
/*
it would be more elegant to load module as a dynamic plugin,
but i would introduce more code and make project less portable
(go dynamic libs only seem to be working on linux).
Thus i use static module import
*/
var ctx *target.Ctx
switch c.Driver {
case "postgres":
ctx = pgsql.TargetCtxNew()
default:
cmn.CndPrintError(args.Raw, fmt.Errorf("Unkown driver: %s", c.Driver))
os.Exit(2)
}
err = ctx.ExecConfig(c, args)
if err != nil {
cmn.CndPrintError(args.Raw, err)
os.Exit(2)
}
}