30 lines
721 B
Go
30 lines
721 B
Go
|
package server
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/rs/zerolog"
|
||
|
|
||
|
"gitlab.com/mstarongitlab/linstrom/server/middlewares"
|
||
|
"gitlab.com/mstarongitlab/linstrom/storage"
|
||
|
)
|
||
|
|
||
|
func ContextGetStorage(w http.ResponseWriter, r *http.Request) *storage.Storage {
|
||
|
val, _ := r.Context().Value(middlewares.CONTEXT_KEY_STORAGE).(*storage.Storage)
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
func ContextGetLogger(w http.ResponseWriter, r *http.Request) *zerolog.Logger {
|
||
|
val, _ := r.Context().Value(middlewares.CONTEXT_KEY_LOGRUS).(*zerolog.Logger)
|
||
|
return val
|
||
|
}
|
||
|
|
||
|
func contextFail(w http.ResponseWriter, contextValName string) {
|
||
|
http.Error(
|
||
|
w,
|
||
|
fmt.Sprintf("failed to get %s from request context", contextValName),
|
||
|
http.StatusInternalServerError,
|
||
|
)
|
||
|
}
|