Files
linuxkit/vendor/github.com/docker/infrakit/pkg/broker/server/server.go
Rolf Neugebauer 48845bcfd9 infrakit: Move the hyperkit instance plugin into the source directory
- The tools directory ideally should not contain source code
- Removes double vendoring of packagages
- Makes it easer to hook the build into the top-level Makefile

Eventually, the plugin should be moved to the infrakit repo.

Signed-off-by: Rolf Neugebauer <rolf.neugebauer@docker.com>
2017-03-25 13:02:45 +01:00

28 lines
619 B
Go

package server
import (
"net"
"net/http"
)
// ListenAndServeOnSocket starts a minimal server (mostly for testing) listening at the given unix socket path.
func ListenAndServeOnSocket(socketPath string, optionalURLPattern ...string) (*Broker, error) {
urlPattern := "/"
if len(optionalURLPattern) > 0 {
urlPattern = optionalURLPattern[0]
}
listener, err := net.Listen("unix", socketPath)
if err != nil {
return nil, err
}
broker := NewBroker()
mux := http.NewServeMux()
mux.Handle(urlPattern, broker)
httpServer := &http.Server{
Handler: mux,
}
go httpServer.Serve(listener)
return broker, nil
}