-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.go
More file actions
103 lines (83 loc) · 4.02 KB
/
Copy pathcontext.go
File metadata and controls
103 lines (83 loc) · 4.02 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package burrow
import (
"context"
"net/http"
"net/netip"
chimw "github.com/go-chi/chi/v5/middleware"
"github.com/oliverandrich/burrow/app"
)
// RequestIsHTTPS reports whether the request should be treated as HTTPS for
// per-request security decisions (CSRF origin check, Secure cookies). Wrapper
// around [app.RequestIsHTTPS]: it honors a trusted reverse proxy's
// X-Forwarded-Proto (see --forwarded-mode) and falls back to r.TLS.
func RequestIsHTTPS(r *http.Request) bool { return app.RequestIsHTTPS(r) }
// WithLayout stores the layout template name in the context. Wrapper around
// [app.WithLayout].
func WithLayout(ctx context.Context, name string) context.Context {
return app.WithLayout(ctx, name)
}
// Layout retrieves the layout template name from the context. Wrapper around
// [app.Layout].
func Layout(ctx context.Context) string { return app.Layout(ctx) }
// WithNavItems stores navigation items in the context. Wrapper around
// [app.WithNavItems].
func WithNavItems(ctx context.Context, items []NavItem) context.Context {
return app.WithNavItems(ctx, items)
}
// NavItems retrieves the navigation items from the context. Wrapper around
// [app.NavItems].
func NavItems(ctx context.Context) []NavItem { return app.NavItems(ctx) }
// WithTemplateExecutor stores the template executor in the context. Wrapper
// around [app.WithTemplateExecutor].
func WithTemplateExecutor(ctx context.Context, exec TemplateExecutor) context.Context {
return app.WithTemplateExecutor(ctx, exec)
}
// TemplateExec retrieves the template executor from the context. Wrapper
// around [app.TemplateExec].
func TemplateExec(ctx context.Context) TemplateExecutor { return app.TemplateExec(ctx) }
// TemplateExecutorFromContext is a deprecated alias for [TemplateExec].
//
//go:fix inline
func TemplateExecutorFromContext(ctx context.Context) TemplateExecutor {
return app.TemplateExec(ctx)
}
// WithAuthChecker stores an AuthChecker in the context. Wrapper around
// [app.WithAuthChecker].
func WithAuthChecker(ctx context.Context, checker AuthChecker) context.Context {
return app.WithAuthChecker(ctx, checker)
}
// WithRequestPath stores the request path in the context. Wrapper around
// [app.WithRequestPath].
func WithRequestPath(ctx context.Context, path string) context.Context {
return app.WithRequestPath(ctx, path)
}
// RequestPath retrieves the request path from the context. Wrapper around
// [app.RequestPath].
func RequestPath(ctx context.Context) string { return app.RequestPath(ctx) }
// IsAuthenticated returns true if the AuthChecker in context reports
// authentication. Wrapper around [app.IsAuthenticated].
func IsAuthenticated(ctx context.Context) bool { return app.IsAuthenticated(ctx) }
// IsStaff returns true if the AuthChecker in context reports staff status.
// Wrapper around [app.IsStaff].
func IsStaff(ctx context.Context) bool { return app.IsStaff(ctx) }
// IsAdmin returns true if the AuthChecker in context reports admin status.
// Wrapper around [app.IsAdmin].
func IsAdmin(ctx context.Context) bool { return app.IsAdmin(ctx) }
// WithContextValue stores a value in the context under the given key. Wrapper
// around [app.WithContextValue].
func WithContextValue(ctx context.Context, key, val any) context.Context {
return app.WithContextValue(ctx, key, val)
}
// ContextValue retrieves a typed value from the context. Wrapper around
// [app.ContextValue].
func ContextValue[T any](ctx context.Context, key any) (T, bool) {
return app.ContextValue[T](ctx, key)
}
// ClientIP returns the client IP stored in the context by burrow's
// server-level ClientIP middleware (configured via --client-ip-mode). Returns
// "" when no middleware ran. Wrapper around [chimw.GetClientIP]. See
// docs/guide/client-ip.md for the trust model.
func ClientIP(ctx context.Context) string { return chimw.GetClientIP(ctx) }
// ClientIPAddr returns the client IP as a [netip.Addr]. Use [netip.Addr.IsValid]
// to check whether a middleware ran. Wrapper around [chimw.GetClientIPAddr].
func ClientIPAddr(ctx context.Context) netip.Addr { return chimw.GetClientIPAddr(ctx) }