-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.go
87 lines (67 loc) · 1.87 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"context"
"fmt"
"net"
"net/http"
"os"
"github.com/arussellsaw/youneedaspreadsheet/pkg/authn"
"github.com/arussellsaw/youneedaspreadsheet/pkg/stripe"
sloggcloud "github.com/arussellsaw/slog-gcloud"
"github.com/monzo/slog"
"github.com/gorilla/mux"
"github.com/arussellsaw/youneedaspreadsheet/handler"
"github.com/arussellsaw/youneedaspreadsheet/pkg/idgen"
"github.com/arussellsaw/youneedaspreadsheet/pkg/logging"
"github.com/arussellsaw/youneedaspreadsheet/pkg/sheets"
"github.com/arussellsaw/youneedaspreadsheet/pkg/store"
"github.com/arussellsaw/youneedaspreadsheet/pkg/truelayer"
"github.com/arussellsaw/youneedaspreadsheet/pkg/util"
)
func main() {
ctx := context.Background()
var logger slog.Logger
sloggcloud.ProjectID = util.Project()
logger = logging.ContextParamLogger{Logger: &sloggcloud.StackDriverLogger{}}
if !util.IsProd() {
logger = logging.ColourLogger{Writer: os.Stdout}
}
logger, err := logging.NewReportingLogger(ctx, logger)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
slog.SetDefaultLogger(logger)
idgen.Init(ctx)
fs, err := store.Init(ctx)
if err != nil {
slog.Error(ctx, "Error intialising FireStore: %s", err)
os.Exit(1)
}
ctx = store.WithStore(ctx, fs)
r := mux.NewRouter()
err = sheets.Init(ctx, r)
if err != nil {
slog.Error(ctx, "Error intialising Google Sheets: %s", err)
os.Exit(1)
}
err = truelayer.Init(ctx, r)
if err != nil {
slog.Error(ctx, "Error intialising Truelayer: %s", err)
os.Exit(1)
}
err = stripe.Init(ctx, r)
if err != nil {
slog.Error(ctx, "Error intialising Stripe: %s", err)
os.Exit(1)
}
handler.Routes(r)
srv := http.Server{
Addr: ":8080",
Handler: sloggcloud.CloudContextMiddleware(authn.UserSessionMiddleware(r)),
BaseContext: func(l net.Listener) context.Context {
return ctx
},
}
slog.Error(ctx, "server exiting: %s", srv.ListenAndServe())
}