2024-03-21 17:15:23 +00:00
|
|
|
package router
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2024-03-21 22:56:24 +00:00
|
|
|
"git.staur.ca/stobbsm/clustvirt/cluster"
|
2024-03-21 17:15:23 +00:00
|
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
)
|
|
|
|
|
2024-03-21 22:56:24 +00:00
|
|
|
// Types that are shared among routers
|
2024-03-21 17:15:23 +00:00
|
|
|
|
2024-03-21 22:56:24 +00:00
|
|
|
// SubRouter defines an interface to be able to add a subrouter to a
|
|
|
|
// chi router
|
|
|
|
type SubRouter interface {
|
|
|
|
MountTo(*cluster.Cluster, chi.Router) error
|
2024-03-21 17:15:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 22:56:24 +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
|
2024-03-21 17:15:23 +00:00
|
|
|
}
|
|
|
|
|
2024-03-21 22:56:24 +00:00
|
|
|
// 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
|