-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
42 lines (33 loc) · 809 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
package main
import (
"net/http"
"github.com/gorilla/mux"
"github.com/graillus/timelapse/internal/api"
"github.com/graillus/timelapse/internal/log"
)
type config struct {
listenAddr string
storagePath string
}
func main() {
cfg := loadConfig()
router := mux.NewRouter()
router.HandleFunc("/health", func(resp http.ResponseWriter, _ *http.Request) {
resp.WriteHeader(http.StatusOK)
})
apiRouter := router.PathPrefix("/api").Subrouter()
api.ConfigureRoutes(apiRouter)
api.StoragePath = cfg.storagePath
go func() {
log.Infof("Server listening to %s", cfg.listenAddr)
err := http.ListenAndServe(cfg.listenAddr, router)
log.Fatalf("Fatal server error: %v", err)
}()
select {}
}
func loadConfig() config {
return config{
listenAddr: "0.0.0.0:8990",
storagePath: "/tmp",
}
}