23 lines
522 B
Go
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
|
|
}
|