package rockets
import (..)
type NewRouterParams struct {
RW *chttp.ReaderWriter
Logger clogger.Logger
}
func NewRouter(p NewRouterParams) *Router {
return &Router{
rw: p.RW,
logger: p.Logger,
}
}
// Router struct implements the `chttp.Router` interface. It holds all the
// dependencies needed for its handlers.
type Router struct {
rw *chttp.ReaderWriter
logger clogger.Logger
}
// Routes returns a list of chttp.Route managed by this Router.
func (ro *Router) Routes() []chttp.Route {
return []chttp.Route{
{
Path: "/rockets/{id}/launch",
Methods: []string{http.MethodPost},
Handler: ro.HandleRocketLaunch,
},
}
}
// HandleRocketLaunch is invoked when a POST request is made to the
// "/rockets/{id}/launch" endpoint
func (ro *Router) HandleRocketLaunch(w http.ResponseWriter, r *http.Request) {
// Handle request here..
}