-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (49 loc) · 1.17 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
package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
func main() {
flag.Parse()
//dsn := "user=postgres password=monkeyintheattic host=%v dbname=threatco"
//*dbLocation = fmt.Sprintf(dsn, GetDBHost())
fmt.Println(*dbLocation)
var c Configuration
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
s := NewServer("1", ":8081", "postgres", *dbLocation)
s.InitializeFromConfig(&c, true)
PassStore(&UploadStore{Files: make(map[string]UploadHandler), Memory: &sync.RWMutex{}, ServerConfig: &c})
ticker := time.NewTicker(time.Duration(c.StatCacheTickRate) * time.Second)
go func() {
for {
select {
case <-ticker.C:
s.UpdateCharts()
go s.updateCache()
case <-sigs:
s.Log.Println("Shutting down")
ticker.Stop()
os.Exit(0)
case <-s.StopCh:
s.Log.Println("Shutting down")
ticker.Stop()
os.Exit(0)
}
}
}()
svr := &http.Server{
Addr: s.Details.Address,
Handler: s.Session.LoadAndSave(s.Gateway),
}
go s.ProcessTransientResponses()
s.LogInfo(fmt.Sprintf("Server started at %s", s.Details.Address))
log.Fatal(svr.ListenAndServe())
}