-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
58 lines (52 loc) · 1.57 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
package main
import (
"flag"
"fmt"
"net/http"
"os"
"quackpipe/config"
"quackpipe/merge"
"quackpipe/model"
"quackpipe/router"
"quackpipe/utils"
)
// initFlags initializes the command line flags
func initFlags() *model.CommandLineFlags {
appFlags := &model.CommandLineFlags{}
appFlags.Host = flag.String("host", "0.0.0.0", "API host. Default 0.0.0.0")
appFlags.Port = flag.String("port", "8123", "API port. Default 8123")
appFlags.Format = flag.String("format", "JSONCompact", "API port. Default JSONCompact")
appFlags.Config = flag.String("config", "", "path to the configuration file")
appFlags.Params = flag.String("params", "", "DuckDB optional parameters. Default to none.")
appFlags.Stdin = flag.Bool("stdin", false, "STDIN query. Default false")
appFlags.Alias = flag.Bool("alias", true, "Built-in CH Aliases. Default true")
flag.Parse()
return appFlags
}
func main() {
config.AppFlags = initFlags()
if *config.AppFlags.Stdin {
rows, duration, format, err := utils.ReadFromScanner(*config.AppFlags)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
results, err := utils.ConversationOfRows(rows, format, duration)
if err != nil {
fmt.Println(err)
os.Exit(1)
} else {
fmt.Println(results)
}
return
}
config.InitConfig(*config.AppFlags.Config)
if config.Config.QuackPipe.Enabled {
merge.Init()
}
r := router.NewRouter(config.AppFlags)
fmt.Printf("QuackPipe API Running: %s:%s\n", *config.AppFlags.Host, *config.AppFlags.Port)
if err := http.ListenAndServe(*config.AppFlags.Host+":"+*config.AppFlags.Port, r); err != nil {
panic(err)
}
}