add docs for DockerCli and NewDockerCli

Signed-off-by: buddhamagnet <buddhamagnet@gmail.com>
This commit is contained in:
buddhamagnet 2015-04-14 14:14:33 +01:00
parent 00eddf5e67
commit 69747b3c1e
1 changed files with 33 additions and 16 deletions

View File

@ -20,24 +20,37 @@ import (
"github.com/docker/docker/registry" "github.com/docker/docker/registry"
) )
// DockerCli represents the docker command line client.
// Instances of the client can be returned from NewDockerCli.
type DockerCli struct { type DockerCli struct {
// proto holds the client protocol i.e. unix.
proto string proto string
// addr holds the client address.
addr string addr string
// configFile holds the configuration file (instance of registry.ConfigFile).
configFile *registry.ConfigFile configFile *registry.ConfigFile
// in holds the input stream and closer (io.ReadCloser) for the client.
in io.ReadCloser in io.ReadCloser
// out holds the output stream (io.Writer) for the client.
out io.Writer out io.Writer
// err holds the error stream (io.Writer) for the client.
err io.Writer err io.Writer
// keyFile holds the key file as a string.
keyFile string keyFile string
// tlsConfig holds the TLS configuration for the client, and will
// set the scheme to https in NewDockerCli if present.
tlsConfig *tls.Config tlsConfig *tls.Config
// scheme holds the scheme of the client i.e. https.
scheme string scheme string
// inFd holds file descriptor of the client's STDIN, if it's a valid file // inFd holds the file descriptor of the client's STDIN (if valid).
inFd uintptr inFd uintptr
// outFd holds file descriptor of the client's STDOUT, if it's a valid file // outFd holds file descriptor of the client's STDOUT (if valid).
outFd uintptr outFd uintptr
// isTerminalIn describes if client's STDIN is a TTY // isTerminalIn indicates whether the client's STDIN is a TTY
isTerminalIn bool isTerminalIn bool
// isTerminalOut describes if client's STDOUT is a TTY // isTerminalOut dindicates whether the client's STDOUT is a TTY
isTerminalOut bool isTerminalOut bool
// transport holds the client transport instance.
transport *http.Transport transport *http.Transport
} }
@ -125,6 +138,10 @@ func (cli *DockerCli) CheckTtyInput(attachStdin, ttyMode bool) error {
return nil return nil
} }
// NewDockerCli returns a DockerCli instance with IO output and error streams set by in, out and err.
// The key file, protocol (i.e. unix) and address are passed in as strings, along with the tls.Config. If the tls.Config
// is set the client scheme will be set to https.
// The client will be given a 32-second timeout (see https://github.com/docker/docker/pull/8035).
func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, addr string, tlsConfig *tls.Config) *DockerCli { func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, addr string, tlsConfig *tls.Config) *DockerCli {
var ( var (
inFd uintptr inFd uintptr
@ -149,15 +166,15 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, keyFile string, proto, a
err = out err = out
} }
// The transport is created here for reuse during the client session // The transport is created here for reuse during the client session.
tr := &http.Transport{ tr := &http.Transport{
TLSClientConfig: tlsConfig, TLSClientConfig: tlsConfig,
} }
// Why 32? See issue 8035 // Why 32? See https://github.com/docker/docker/pull/8035.
timeout := 32 * time.Second timeout := 32 * time.Second
if proto == "unix" { if proto == "unix" {
// no need in compressing for local communications // No need for compression in local communications.
tr.DisableCompression = true tr.DisableCompression = true
tr.Dial = func(_, _ string) (net.Conn, error) { tr.Dial = func(_, _ string) (net.Conn, error) {
return net.DialTimeout(proto, addr, timeout) return net.DialTimeout(proto, addr, timeout)