Skip to content
Find file
5233dc7
34 lines (27 sloc) 542 Bytes
package lion
type Module interface {
Resource
Base() string
Routes(*Router)
}
type ModuleRequirements interface {
Requires() []string
}
func (r *Router) Module(modules ...Module) {
for _, m := range modules {
r.registerModule(m)
}
}
func (r *Router) registerModule(m Module) {
g := r.Group(m.Base())
if req, ok := m.(ModuleRequirements); ok {
for _, dep := range req.Requires() {
if !r.hasNamed(dep) {
panic("Unmet middleware requirement for " + dep)
}
g.UseNamed(dep)
}
}
g.Resource("/", m)
m.Routes(g)
}
Something went wrong with that request. Please try again.