-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 880 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 (
"log"
"net/http"
"time"
"github.com/gorilla/mux"
"github.com/rs/cors"
"github.com/urfave/negroni"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
storage, err := NewEnvStorage()
if err != nil {
if err == ErrCouldNotConnectToStorage {
log.Fatal("[main] unable to connect to configured storage")
}
log.Fatal(err.Error())
}
syncer := NewSyncer(storage, 1*time.Hour)
go syncer.Run()
server := &server{
router: mux.NewRouter(),
storage: storage,
}
server.routes()
n := negroni.Classic()
n.Use(cors.Default())
n.UseHandler(server)
s := &http.Server{
Addr: ":8000",
Handler: n,
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
}
// Can't be bothered to make TLS configurable. Just
// use a reverse proxy for that...
return s.ListenAndServe()
}