github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/client/container_resize.go (about)

     1  package client
     2  
     3  import (
     4  	"net/url"
     5  	"strconv"
     6  
     7  	"github.com/docker/docker/api/types"
     8  	"golang.org/x/net/context"
     9  )
    10  
    11  // ContainerResize changes the size of the tty for a container.
    12  func (cli *Client) ContainerResize(ctx context.Context, containerID string, options types.ResizeOptions) error {
    13  	return cli.resize(ctx, "/containers/"+containerID, options.Height, options.Width)
    14  }
    15  
    16  // ContainerExecResize changes the size of the tty for an exec process running inside a container.
    17  func (cli *Client) ContainerExecResize(ctx context.Context, execID string, options types.ResizeOptions) error {
    18  	return cli.resize(ctx, "/exec/"+execID, options.Height, options.Width)
    19  }
    20  
    21  func (cli *Client) resize(ctx context.Context, basePath string, height, width uint) error {
    22  	query := url.Values{}
    23  	query.Set("h", strconv.Itoa(int(height)))
    24  	query.Set("w", strconv.Itoa(int(width)))
    25  
    26  	resp, err := cli.post(ctx, basePath+"/resize", query, nil, nil)
    27  	ensureReaderClosed(resp)
    28  	return err
    29  }