-
Notifications
You must be signed in to change notification settings - Fork 45
/
main.go
87 lines (74 loc) · 2.05 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"flag"
"net"
"net/http"
_ "net/http/pprof"
"os"
"runtime"
// Backend Side-Effect imports, ie load the providers into registry but
// config will determine if they get used.
// if you are building custom daemon, you can cherry pick sources you care about
_ "github.com/dataux/dataux/backends/bigtable"
_ "github.com/dataux/dataux/backends/cassandra"
_ "github.com/dataux/dataux/backends/datastore"
_ "github.com/dataux/dataux/backends/elasticsearch"
_ "github.com/dataux/dataux/backends/files"
_ "github.com/dataux/dataux/backends/kubernetes"
_ "github.com/dataux/dataux/backends/mongo"
// Frontend's side-effect imports
_ "github.com/dataux/dataux/frontends/mysqlfe"
u "github.com/araddon/gou"
"github.com/dataux/dataux/proxy"
)
var (
configFile string
pprofPort string
workerCt int
logLevel = "info"
)
func init() {
flag.StringVar(&configFile, "config", "dataux.conf", "dataux proxy config file")
flag.StringVar(&logLevel, "loglevel", "info", "logging [ debug,info,warn,error ]")
flag.StringVar(&pprofPort, "pprof", ":18008", "pprof and metrics port")
flag.IntVar(&workerCt, "workerct", 3, "Number of worker nodes")
flag.Parse()
}
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
u.SetupLogging(logLevel)
u.SetColorIfTerminal()
// First try to look for dataux.conf or provided conf file
// if that fails then use the empty default which means api's
// etc can be used to dynamically define schema etc
_, err := proxy.LoadConfig(configFile)
if err != nil {
_, err = proxy.LoadConfigString(DefaultConfig)
if err != nil {
os.Exit(1)
}
}
// go profiling
if pprofPort != "" {
conn, err := net.Listen("tcp", pprofPort)
if err != nil {
u.Warnf("Error listening on %s: %v", pprofPort, err)
os.Exit(1)
}
go func() {
if err := http.Serve(conn, http.DefaultServeMux); err != nil {
u.Errorf("Error from profile HTTP server: %v", err)
}
conn.Close()
}()
}
proxy.RunDaemon(true, workerCt)
}
var DefaultConfig = `
frontends : [
{
type : mysql
address : "0.0.0.0:4000"
}
]
`