3
0

Config. environment (throughenv var 'ENVIRONMENT')

This commit is contained in:
Denis Arh
2020-11-04 14:38:07 +01:00
parent 7666fe2d62
commit ed8fc547f7
12 changed files with 106 additions and 76 deletions
+5 -9
View File
@@ -9,20 +9,16 @@ import (
type ctxKeyDebug struct{}
// Packs remote address to context
func DebugToContext(next http.Handler) http.Handler {
if true {
// debug disabled
return next
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)))
})
}
return http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
next.ServeHTTP(w, req.WithContext(context.WithValue(req.Context(), ctxKeyDebug{}, true)))
})
}
// DebugFromContext returns remote IP address from context
func DebugFromContext(ctx context.Context) bool {
return true
debug, ok := ctx.Value(ctxKeyDebug{}).(bool)
return ok && debug
}