-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
51 lines (40 loc) · 867 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 (
"database/sql"
"flag"
"os"
"github.com/minond/captainslog/querier/repl"
"github.com/minond/captainslog/querier/repository"
internal "github.com/minond/captainslog/shared/service"
_ "github.com/lib/pq"
)
var (
replMode = flag.Bool("repl", false, "start repl instead of server")
)
func main() {
flag.Parse()
if *replMode {
runRepl()
} else {
runServer()
}
}
func runServer() {
internal.InitGlobalTracer("querier")
db, err := sql.Open("postgres", os.Getenv("QUERIER_DB_CONN"))
if err != nil {
panic(err)
}
repo := repository.New(db)
service := NewService(repo)
server := internal.NewServer(os.Getenv("QUERIER_HTTP_LISTEN"), service)
server.Run()
}
func runRepl() {
config := ConfigFromEnv()
db, err := sql.Open("postgres", config.dbConn)
if err != nil {
panic(err)
}
repl.New(repository.New(db)).Run()
}