-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
47 lines (41 loc) · 1.28 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
package main
import (
"github.com/wolfsblu/go-chef/api"
"github.com/wolfsblu/go-chef/domain"
"github.com/wolfsblu/go-chef/infra/env"
"github.com/wolfsblu/go-chef/infra/handlers"
"github.com/wolfsblu/go-chef/infra/jobs"
"github.com/wolfsblu/go-chef/infra/routing"
"github.com/wolfsblu/go-chef/infra/smtp"
"github.com/wolfsblu/go-chef/infra/sqlite"
"log"
"net/http"
)
func main() {
env.Load()
notifier := smtp.NewSMTPMailer()
store, err := sqlite.NewSqliteStore()
if err != nil {
log.Fatalln("failed to initialize sqlite connection:", err)
}
err = store.Migrate()
if err != nil {
log.Fatalln("failed to apply database migrations:", err)
}
recipeService := domain.NewRecipeService(notifier, store)
recipeHandler := handlers.NewRecipeHandler(recipeService)
securityHandler := handlers.NewSecurityHandler(recipeService)
errorHandler := recipeHandler.CustomErrorHandler
apiServer, err := api.NewServer(recipeHandler, securityHandler, api.WithErrorHandler(errorHandler))
if err != nil {
log.Fatalln("failed to start api server:", err)
}
jobs.StartScheduler(recipeService)
defer jobs.QuitScheduler()
host := env.MustGet("HOST")
mux := routing.NewServeMux(apiServer)
err = http.ListenAndServe(host, mux)
if err != nil {
log.Fatalln("failed to start web server:", err)
}
}