-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
86 lines (73 loc) · 1.93 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
//go:build !lambda
package main
import (
"context"
"fmt"
"github.com/gw2auth/gw2auth.com-api/telemetry"
"github.com/labstack/echo/v4"
"io"
"os"
"os/signal"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt)
defer stop()
err := WithTelemetry(
ctx,
"GW2AuthAPILambda",
func(ctx context.Context, t *telemetry.Telemetry) error {
return WithEchoServer(ctx, func(ctx context.Context, app *echo.Echo) error {
go func() {
<-ctx.Done()
if err := app.Shutdown(context.Background()); err != nil {
fmt.Printf("error shutting down echo server: %v\n", err)
} else {
fmt.Println("shutdown complete")
}
}()
return app.Start(":8090")
}, WithFlusher(t))
},
telemetry.WithResource(telemetry.NewLocalResource),
telemetry.WithTracerProvider(telemetry.NewLocalTracerProvider),
telemetry.WithLoggerProvider(telemetry.NewLocalLoggerProvider),
)
if err != nil {
panic(err)
}
}
func loadSecrets(ctx context.Context) (Secrets, error) {
pub1, err := loadFile("/Users/felix/.gw2auth/session_id_rsa_1.pub")
if err != nil {
return Secrets{}, err
}
pub2, err := loadFile("/Users/felix/.gw2auth/session_id_rsa_2.pub")
if err != nil {
return Secrets{}, err
}
priv, err := loadFile("/Users/felix/.gw2auth/session_id_rsa_2")
if err != nil {
return Secrets{}, err
}
return Secrets{
DatabaseURL: "postgres://gw2auth_app:@localhost:26257/defaultdb",
SessionRSAPublicKid1: "0412f229-a208-45d1-8c00-93f1ff92d24b",
SessionRSAPublicKid2: "dbb703c6-87ec-4329-844e-01d03e373dac",
SessionRSAPrivateKid2: "dbb703c6-87ec-4329-844e-01d03e373dac",
SessionRSAPublicPEM1: pub1,
SessionRSAPublicPEM2: pub2,
SessionRSAPrivatePEM2: priv,
}, nil
}
func loadFile(path string) (string, error) {
f, err := os.Open(path)
if err != nil {
return "", err
}
defer f.Close()
b, err := io.ReadAll(f)
if err != nil {
return "", err
}
return string(b), nil
}