diff --git a/http.go b/http.go index 5310151..01025fd 100644 --- a/http.go +++ b/http.go @@ -136,13 +136,13 @@ func buildHandler() (http.Handler, error) { // Blog rootPath := "/" blogPath := "/blog" - if routePatterns := routesToStringSlice(r.Routes()); !routePatterns.has(rootPath) { + if !r.Match(chi.NewRouteContext(), http.MethodGet, rootPath) { r.With(cacheMiddleware, minifier.Middleware).Get(rootPath, serveHome("", NONE)) r.With(cacheMiddleware, minifier.Middleware).Get(rootPath+rssPath, serveHome("", RSS)) r.With(cacheMiddleware, minifier.Middleware).Get(rootPath+jsonPath, serveHome("", JSON)) r.With(cacheMiddleware, minifier.Middleware).Get(rootPath+atomPath, serveHome("", ATOM)) r.With(cacheMiddleware, minifier.Middleware).Get(paginationPath, serveHome("", NONE)) - } else if !routePatterns.has(blogPath) { + } else if !r.Match(chi.NewRouteContext(), http.MethodGet, blogPath) { r.With(cacheMiddleware, minifier.Middleware).Get(blogPath, serveHome(blogPath, NONE)) r.With(cacheMiddleware, minifier.Middleware).Get(blogPath+rssPath, serveHome(blogPath, RSS)) r.With(cacheMiddleware, minifier.Middleware).Get(blogPath+jsonPath, serveHome(blogPath, JSON)) @@ -155,13 +155,6 @@ func buildHandler() (http.Handler, error) { return r, nil } -func routesToStringSlice(routes []chi.Route) (ss stringSlice) { - for _, r := range routes { - ss = append(ss, r.Pattern) - } - return -} - type dynamicHandler struct { realHandler http.Handler changeMutex *sync.Mutex diff --git a/utils.go b/utils.go index 7f54f73..b82620d 100644 --- a/utils.go +++ b/utils.go @@ -5,17 +5,6 @@ import ( "strings" ) -type stringSlice []string - -func (s stringSlice) has(value string) bool { - for _, v := range s { - if v == value { - return true - } - } - return false -} - func urlize(str string) string { newStr := "" for _, c := range strings.Split(strings.ToLower(str), "") {