cleaned up the api for adding routes (it does it automatically when you create the route).
Added a function to the server to announce registered routes.
This commit is contained in:
parent
a72b54a114
commit
14cbf49e9a
@ -25,13 +25,15 @@ const (
|
||||
UNDEFINED
|
||||
)
|
||||
|
||||
func NewApiRoute(pattern string) *ApiRoute {
|
||||
func NewApiRoute(serv *VinegarServlet, pattern string) *ApiRoute {
|
||||
functionMap := make(map[HttpMethod]VinegarHandlerFunction)
|
||||
ancestorRoute := NewServletRoute(pattern, createMethodHandler(&functionMap))
|
||||
route := ApiRoute{
|
||||
ancestorRoute,
|
||||
&functionMap,
|
||||
}
|
||||
|
||||
serv.AddRoute(route.VinegarRoute)
|
||||
return &route
|
||||
}
|
||||
|
||||
|
||||
@ -52,6 +52,7 @@ func NewServletRoute(routePattern string, handleFunc VinegarHandlerFunction) *Vi
|
||||
}
|
||||
|
||||
func (s *VinegarServlet) AddRoute(route *VinegarRoute) {
|
||||
route.Announce()
|
||||
s.Routes = append(s.Routes, route)
|
||||
}
|
||||
|
||||
@ -78,10 +79,8 @@ func (s *VinegarServlet) Start() {
|
||||
|
||||
}
|
||||
|
||||
func (s *VinegarServlet) PrintRoutes() {
|
||||
for _, route := range s.Routes {
|
||||
log.Println(route.Pattern.String())
|
||||
}
|
||||
func (r *VinegarRoute) Announce() {
|
||||
log.Printf("Added route for [%s]\n", r.Pattern.String())
|
||||
}
|
||||
|
||||
func SendError(w http.ResponseWriter, code int, msg string) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user