-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
73 lines (52 loc) · 1.66 KB
/
app.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
package main
import (
"flag"
"fmt"
"log"
"github.com/julienschmidt/httprouter"
"github.com/tokopedia/sqlt"
"github.com/antony/polling/config"
"github.com/google/gops/agent"
"github.com/tokopedia/logging/tracer"
"gopkg.in/tokopedia/grace.v1"
"gopkg.in/tokopedia/logging.v1"
_pdaRepository "github.com/antony/polling/polling_defined_answer/repository"
_puaRepository "github.com/antony/polling/polling_user_answer/repository"
pollingDelivery "github.com/antony/polling/polling/delivery/http"
pollingRepository "github.com/antony/polling/polling/repository"
pollingUsecase "github.com/antony/polling/polling/usecase"
_ "github.com/lib/pq"
)
var cfg *config.Config
func init() {
var ok bool
cfg, ok = config.NewConfig([]string{"./files/etc/polling"}...)
if !ok {
fmt.Println("Error opening config files")
}
}
func main() {
flag.Parse()
logging.LogInit()
debug := logging.Debug.Println
debug("app started") // message will not appear unless run with -debug switch
if err := agent.Listen(&agent.Options{}); err != nil {
log.Fatal(err)
}
//Open connection to db
db, err := sqlt.Open("postgres", cfg.Polling.DB)
if err != nil {
log.Println("Error opening db")
return
}
router := httprouter.New()
//init polling handler
pp := pollingRepository.NewPostgresPollingRepository(db)
pdap := _pdaRepository.NewPostgresPollingDefinedAnswerRepository(db)
puap := _puaRepository.NewPollingUserAnswerPostgresRepository(db)
pu := pollingUsecase.NewPollingUsecase(pp, pdap, puap)
pollingDelivery.NewPollingHttpHandler(router, pu)
go logging.StatsLog()
tracer.Init(&tracer.Config{Port: 8700, Enabled: true})
log.Fatal(grace.Serve(":9000", router))
}