Skip to content

Commit

Permalink
add not found route
Browse files Browse the repository at this point in the history
  • Loading branch information
steviebps committed Jul 4, 2023
1 parent 8b1c217 commit f5b3ad2
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,20 @@ func handle(hc HandlerConfig) http.Handler {
logger := hc.Logger.Named("http")
strg := hc.Storage
mux := http.NewServeMux()

mux.HandleFunc("/v1/", func(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
requestLogger := logger.With("method", r.Method, "path", r.URL.Path)
loggerCtx := hclog.WithContext(ctx, requestLogger)

path := strings.TrimPrefix(r.URL.Path, "/v1")
if path == "/" {
http.NotFound(w, r)
return
}

switch r.Method {
case http.MethodGet:
if path == "/" {
err := fmt.Errorf("path cannot be %q", path)
requestLogger.Error(err.Error())
handleError(w, http.StatusNotFound, err)
return
}

entry, err := strg.Get(loggerCtx, utils.EnsureTrailingSlash(path))
if err != nil {
requestLogger.Error(err.Error())
Expand Down

0 comments on commit f5b3ad2

Please sign in to comment.