2024-03-24 04:05:06 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"git.staur.ca/stobbsm/clustvirt/cluster"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Types that are shared among routers
|
|
|
|
|
|
|
|
// SubRouter defines an interface to be able to add a subrouter to a
|
|
|
|
// chi router
|
|
|
|
type SubRouter interface {
|
2024-03-24 05:59:56 +00:00
|
|
|
// MountTo needs the cluster handle and the mux to add to
|
|
|
|
MountTo(*cluster.Cluster, *http.ServeMux) error
|
|
|
|
// Prefix returns the path prefix
|
|
|
|
Prefix() string
|
2024-03-24 04:05:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Route defines a route that should be added to a chi router or
|
|
|
|
// subrouter
|
|
|
|
type Route struct {
|
|
|
|
Method string
|
|
|
|
Path string
|
|
|
|
Handler RouteHandler
|
|
|
|
}
|
|
|
|
|
|
|
|
// RouteHandler gets the active cluster for the server to inject into
|
|
|
|
// the http.HandlerFunc that is then returned
|
|
|
|
type RouteHandler func(*cluster.Cluster) http.HandlerFunc
|