1
0
mirror of https://github.com/rancher/steve.git synced 2025-04-28 11:14:43 +00:00
steve/pkg/server/router/router.go

42 lines
1.3 KiB
Go
Raw Normal View History

2019-08-14 18:08:34 +00:00
package router
import (
"net/http"
"github.com/gorilla/mux"
)
2020-01-31 05:37:59 +00:00
type RouterFunc func(h Handlers) http.Handler
2019-08-14 18:08:34 +00:00
type Handlers struct {
K8sResource http.Handler
GenericResource http.Handler
2019-08-14 20:39:08 +00:00
APIRoot http.Handler
2019-08-14 18:08:34 +00:00
K8sProxy http.Handler
2020-01-31 05:37:59 +00:00
Next http.Handler
2019-08-14 18:08:34 +00:00
}
func Routes(h Handlers) http.Handler {
m := mux.NewRouter()
m.UseEncodedPath()
m.StrictSlash(true)
2020-01-31 05:37:59 +00:00
m.Path("/").Handler(h.APIRoot).HeadersRegexp("Accepts", ".*json.*")
2019-08-14 20:39:08 +00:00
m.Path("/{name:v1}").Handler(h.APIRoot)
2019-08-14 18:08:34 +00:00
m.Path("/v1/{group}.{version}.{resource}").Handler(h.K8sResource)
m.Path("/v1/{group}.{version}.{resource}/{nameorns}").Handler(h.K8sResource)
m.Path("/v1/{group}.{version}.{resource}/{namespace}/{name}").Handler(h.K8sResource)
2020-01-31 05:37:59 +00:00
m.Path("/v1/{group}.{version}.{resource}/{nameorns}").Queries("action", "{action}").Handler(h.K8sResource)
m.Path("/v1/{group}.{version}.{resource}/{namespace}/{name}").Queries("action", "{action}").Handler(h.K8sResource)
m.Path("/v1/{type:schemas}/{name:.*}").Handler(h.GenericResource)
2019-08-14 18:08:34 +00:00
m.Path("/v1/{type}").Handler(h.GenericResource)
m.Path("/v1/{type}/{name}").Handler(h.GenericResource)
2020-01-31 05:37:59 +00:00
m.PathPrefix("/api").Handler(h.K8sProxy)
m.PathPrefix("/openapi").Handler(h.K8sProxy)
m.PathPrefix("/version").Handler(h.K8sProxy)
m.NotFoundHandler = h.Next
2019-08-14 18:08:34 +00:00
return m
}