Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request moby#5 from crosbymichael/update-events
Update events to consume the json stream and not buffer in memory
- Loading branch information
Showing
3 changed files
with
79 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/samalba/dockerclient" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func eventCallback(e *dockerclient.Event, args ...interface{}) { | ||
log.Println(e) | ||
} | ||
|
||
func waitForInterrupt() { | ||
sigChan := make(chan os.Signal, 1) | ||
signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT) | ||
for _ = range sigChan { | ||
os.Exit(0) | ||
} | ||
} | ||
|
||
func main() { | ||
docker, err := dockerclient.NewDockerClient(os.Getenv("DOCKER_HOST")) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
docker.StartMonitorEvents(eventCallback) | ||
|
||
waitForInterrupt() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dockerclient | ||
|
||
import ( | ||
"net" | ||
"net/http" | ||
"net/url" | ||
) | ||
|
||
func newHTTPClient(u *url.URL) *http.Client { | ||
httpTransport := &http.Transport{} | ||
if u.Scheme == "unix" { | ||
socketPath := u.Path | ||
unixDial := func(proto string, addr string) (net.Conn, error) { | ||
return net.Dial("unix", socketPath) | ||
} | ||
httpTransport.Dial = unixDial | ||
// Override the main URL object so the HTTP lib won't complain | ||
u.Scheme = "http" | ||
u.Host = "unix.sock" | ||
} | ||
u.Path = "" | ||
return &http.Client{Transport: httpTransport} | ||
} |