github.com/walkingsparrow/docker@v1.4.2-0.20151218153551-b708a2249bfa/api/client/lib/container_attach.go (about)

     1  package lib
     2  
     3  import (
     4  	"net/url"
     5  
     6  	"github.com/docker/docker/api/types"
     7  )
     8  
     9  // ContainerAttach attaches a connection to a container in the server.
    10  // It returns a types.HijackedConnection with the hijacked connection
    11  // and the a reader to get output. It's up to the called to close
    12  // the hijacked connection by calling types.HijackedResponse.Close.
    13  func (cli *Client) ContainerAttach(options types.ContainerAttachOptions) (types.HijackedResponse, error) {
    14  	query := url.Values{}
    15  	if options.Stream {
    16  		query.Set("stream", "1")
    17  	}
    18  	if options.Stdin {
    19  		query.Set("stdin", "1")
    20  	}
    21  	if options.Stdout {
    22  		query.Set("stdout", "1")
    23  	}
    24  	if options.Stderr {
    25  		query.Set("stderr", "1")
    26  	}
    27  
    28  	headers := map[string][]string{"Content-Type": {"text/plain"}}
    29  	return cli.postHijacked("/containers/"+options.ContainerID+"/attach", query, nil, headers)
    30  }