-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
54 lines (46 loc) · 1.19 KB
/
config.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
package model
import (
"context"
"net/http"
"github.com/interline-io/transitland-lib/tl"
"github.com/interline-io/transitland-mw/jobs"
"github.com/interline-io/transitland-server/internal/clock"
)
type Config struct {
Finder Finder
RTFinder RTFinder
GbfsFinder GbfsFinder
Whoami Whoami
Checker Checker
JobQueue jobs.JobQueue
Clock clock.Clock
Secrets []tl.Secret
ValidateLargeFiles bool
DisableImage bool
RestPrefix string
Storage string
RTStorage string
}
var finderCtxKey = &contextKey{"finderConfig"}
type contextKey struct {
name string
}
func ForContext(ctx context.Context) Config {
raw, ok := ctx.Value(finderCtxKey).(Config)
if !ok {
return Config{}
}
return raw
}
func WithConfig(ctx context.Context, cfg Config) context.Context {
r := context.WithValue(ctx, finderCtxKey, cfg)
return r
}
func AddConfig(cfg Config) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
r = r.WithContext(WithConfig(r.Context(), cfg))
next.ServeHTTP(w, r)
})
}
}