Matthew Stobbs
77c34481ce
- instead of having to make a new type for each set of routes, now we just need to define the routes as an exported variable. - TODO: add a mechanism to add routes externally to the server setup
29 lines
694 B
Go
29 lines
694 B
Go
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 {
|
|
// MountTo needs the path prefix, cluster handle and the mux to add to
|
|
MountTo(string, *cluster.Cluster, *http.ServeMux) error
|
|
}
|
|
|
|
// 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
|