Moving server files to ./server

This commit is contained in:
Corteza Monorepo Migrator
2022-11-14 09:26:39 +01:00
parent 204738f7c9
commit 683c7c56e2
5750 changed files with 0 additions and 26430 deletions
+24
View File
@@ -0,0 +1,24 @@
package api
import (
"context"
"net/http"
)
// Debug context
type ctxKeyDebug struct{}
// Packs remote address to context
func DebugToContext(production bool) func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
next.ServeHTTP(w, req.WithContext(context.WithValue(req.Context(), ctxKeyDebug{}, !production)))
})
}
}
// DebugFromContext returns remote IP address from context
func DebugFromContext(ctx context.Context) bool {
debug, ok := ctx.Value(ctxKeyDebug{}).(bool)
return ok && debug
}