Пример #1
0
// ServeHTTP runs an HTTP server on the specified local address.  This
// serves connections forever, and probably wants to be run in a
// goroutine.  Panics on any error in the initial setup or in
// accepting connections.
func ServeHTTP(
	coord coordinate.Coordinate,
	laddr string,
) {
	handler := restserver.NewRouter(coord)
	server := &http.Server{
		Addr:    laddr,
		Handler: handler,
	}
	server.ListenAndServe()
}
Пример #2
0
func init() {
	// This sets up an object stack where the REST client code talks
	// to the REST server code, which points at an in-memory backend.
	memBackend := memory.NewWithClock(coordinatetest.Clock)
	router := restserver.NewRouter(memBackend)
	server := httptest.NewServer(router)
	backend, err := restclient.New(server.URL)
	if err != nil {
		panic(err)
	}
	coordinatetest.Coordinate = backend
}