linstrom/server/utils.go

32 lines
792 B
Go

package server
import (
"net/http"
"github.com/rs/zerolog/hlog"
"gitlab.com/mstarongitlab/goutils/other"
"gitlab.com/mstarongitlab/linstrom/storage"
)
func placeholderEndpoint(w http.ResponseWriter, r *http.Request) {
hlog.FromRequest(r).Error().Stringer("url", r.URL).Msg("Placeholder endpoint accessed")
other.HttpErr(
w,
HttpErrIdPlaceholder,
"Endpoint not implemented yet, this is a placeholder",
http.StatusInternalServerError,
)
}
func StorageFromRequest(r *http.Request) *storage.Storage {
store, ok := r.Context().Value(ContextKeyStorage).(*storage.Storage)
if !ok {
hlog.FromRequest(r).Fatal().Msg("Failed to get storage reference from context")
return nil
}
return store
}
func NoteIdFromRequest(r *http.Request) string {
return r.PathValue("noteId")
}