Beispiel #1
0
func NewHTTPHandler(ds Datastore) http.Handler {
	router := httprouter.New()

	api := &httpAPI{
		Store: ds,
	}

	router.Handler("GET", status.Path, status.SimpleHandler(ds.Ping))

	router.PUT("/services/:service", api.AddService)
	router.DELETE("/services/:service", api.RemoveService)
	router.GET("/services/:service", api.GetServiceStream)

	router.PUT("/services/:service/meta", api.SetServiceMeta)
	router.GET("/services/:service/meta", api.GetServiceMeta)

	router.PUT("/services/:service/instances/:instance_id", api.AddInstance)
	router.DELETE("/services/:service/instances/:instance_id", api.RemoveInstance)
	router.GET("/services/:service/instances", api.GetInstances)

	router.PUT("/services/:service/leader", api.SetLeader)
	router.GET("/services/:service/leader", api.GetLeader)

	router.GET("/ping", func(http.ResponseWriter, *http.Request, httprouter.Params) {})

	return router
}
Beispiel #2
0
func httpServer(sn *subnet.SubnetManager, publicIP, port string) error {
	overlayListener, err := net.Listen("tcp", net.JoinHostPort(sn.Lease().Network.IP.String(), port))
	if err != nil {
		return err
	}
	publicListener, err := net.Listen("tcp", net.JoinHostPort(publicIP, port))

	http.HandleFunc("/ping", func(http.ResponseWriter, *http.Request) {})
	status.AddHandler(status.SimpleHandler(func() error {
		return pingLeases(sn.Leases())
	}))
	go http.Serve(overlayListener, nil)
	go http.Serve(publicListener, nil)
	return nil
}
Beispiel #3
0
func apiHandler(rtr *Router) http.Handler {
	r := martini.NewRouter()
	m := martini.New()
	m.Map(log.New(os.Stdout, "[router] ", log.LstdFlags|log.Lmicroseconds))
	m.Use(martini.Logger())
	m.Use(martini.Recovery())
	m.Use(render.Renderer())
	m.Action(r.Handle)
	m.Map(rtr)

	r.Get(status.Path, status.SimpleHandler(rtr.HTTP.Ping).ServeHTTP)

	r.Post("/routes", binding.Bind(router.Route{}), createRoute)
	r.Put("/routes/:route_type/:id", binding.Bind(router.Route{}), updateRoute)
	r.Get("/routes", getRoutes)
	r.Get("/routes/:route_type/:id", getRoute)
	r.Delete("/routes/:route_type/:id", deleteRoute)
	r.Get("/events", streamEvents)
	r.Any("/debug/**", pprof.Handler.ServeHTTP)
	return m
}