mirror of
https://github.com/linuxkit/linuxkit.git
synced 2026-01-17 04:42:16 +00:00
- 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>
28 lines
619 B
Go
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
|
|
}
|