Пример #1
0
func (s *Server) routeHandler() http.Handler {
	return routing.NewRouteHandler(
		routing.PrefixSeq("/v1",
			s.ClassroomsRoutes(),
		),
		routing.Any(http.FileServer(http.Dir(s.config.UiDir))),
	)
}
Пример #2
0
func (s *Server) ClassroomsRoutes() routing.Matcher {
	resource := &classroomsResource{
		store:  s.store,
		logger: s.logger.WithContext(map[string]interface{}{"resource": "classrooms"}),
	}
	return routing.PrefixSeq("/classrooms",
		routing.StringPart(func(classroomName string) routing.Matcher {
			return routing.EndSeq(
				routing.GETFunc(resource.wrapWithClassroom(classroomName, resource.GetClassroom)),
				routing.PUTFunc(resource.wrapWithClassroom(classroomName, resource.UpdateClassroom)),
				routing.DELETEFunc(resource.DeleteClassroom(classroomName)),
				routing.MethodNotAllowed,
			)
		}),
		routing.EndSeq(
			routing.POSTFunc(wrap(resource.logger, resource.CreateClassroom)),
			routing.MethodNotAllowed,
		),
	)
}