goshort/internal/server/short/router.go
2023-08-17 14:14:59 -03:00

23 lines
522 B
Go

package shortserver
import (
"net/http"
"github.com/go-chi/chi/v5"
)
func NewShortRouter(h *ShortHandler) http.Handler {
mux := chi.NewRouter()
// Match the short url
mux.Get("/{short}", h.FindShort)
// Match everything else with an empty handler,
// so chi doesn't respond with a 404 by default.
// We do this so that the next handler, the static handler,
// can receive non-matching requests and handle them.
mux.Get("/*", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {}))
return mux
}