-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
57 lines (48 loc) · 1.62 KB
/
server.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
package handle
import (
"context"
"net/http"
"github.com/MicahParks/jwkset"
"go.uber.org/zap"
"github.com/MicahParks/magiclinksdev/config"
"github.com/MicahParks/magiclinksdev/email"
"github.com/MicahParks/magiclinksdev/magiclink"
"github.com/MicahParks/magiclinksdev/rlimit"
"github.com/MicahParks/magiclinksdev/storage"
)
// Server is the magiclinksdev server.
type Server struct {
Config config.Config
Ctx context.Context
EmailProvider email.Provider
HTTPMux *http.ServeMux
JWKS jwkset.JWKSet[storage.JWKSetCustomKeyMeta]
Limiter rlimit.RateLimiter
MagicLink magiclink.MagicLink[storage.MagicLinkCustomCreateArgs, storage.MagicLinkCustomReadResponse, storage.JWKSetCustomKeyMeta]
Store storage.Storage
Sugared *zap.SugaredLogger
MiddlewareHook MiddlewareHook
}
// MiddlewareToggle contains fields to turn middleware on and off.
type MiddlewareToggle struct {
Admin bool
Authn bool
CommitTx bool
RateLimit bool
}
// MiddlewareOptions contains options for applying middleware.
type MiddlewareOptions struct {
Handler http.Handler
Path string
Toggle MiddlewareToggle
}
// MiddlewareHook is a function that can be used to modify the middleware options.
type MiddlewareHook interface {
Hook(options MiddlewareOptions) MiddlewareOptions
}
// MiddlewareHookFunc is a function that can be used to modify the middleware options.
type MiddlewareHookFunc func(options MiddlewareOptions) MiddlewareOptions
// Hook implements the MiddlewareHook interface.
func (h MiddlewareHookFunc) Hook(options MiddlewareOptions) MiddlewareOptions {
return h(options)
}