podman

Форк
0
74 строки · 2.0 Кб
1
package docker
2

3
import (
4
	"io"
5
	"net/http"
6
)
7

8
// AttachToContainerOptions is the set of options that can be used when
9
// attaching to a container.
10
//
11
// See https://goo.gl/JF10Zk for more details.
12
type AttachToContainerOptions struct {
13
	Container    string    `qs:"-"`
14
	InputStream  io.Reader `qs:"-"`
15
	OutputStream io.Writer `qs:"-"`
16
	ErrorStream  io.Writer `qs:"-"`
17

18
	// If set, after a successful connect, a sentinel will be sent and then the
19
	// client will block on receive before continuing.
20
	//
21
	// It must be an unbuffered channel. Using a buffered channel can lead
22
	// to unexpected behavior.
23
	Success chan struct{}
24

25
	// Override the key sequence for detaching a container.
26
	DetachKeys string
27

28
	// Use raw terminal? Usually true when the container contains a TTY.
29
	RawTerminal bool `qs:"-"`
30

31
	// Get container logs, sending it to OutputStream.
32
	Logs bool
33

34
	// Stream the response?
35
	Stream bool
36

37
	// Attach to stdin, and use InputStream.
38
	Stdin bool
39

40
	// Attach to stdout, and use OutputStream.
41
	Stdout bool
42

43
	// Attach to stderr, and use ErrorStream.
44
	Stderr bool
45
}
46

47
// AttachToContainer attaches to a container, using the given options.
48
//
49
// See https://goo.gl/JF10Zk for more details.
50
func (c *Client) AttachToContainer(opts AttachToContainerOptions) error {
51
	cw, err := c.AttachToContainerNonBlocking(opts)
52
	if err != nil {
53
		return err
54
	}
55
	return cw.Wait()
56
}
57

58
// AttachToContainerNonBlocking attaches to a container, using the given options.
59
// This function does not block.
60
//
61
// See https://goo.gl/NKpkFk for more details.
62
func (c *Client) AttachToContainerNonBlocking(opts AttachToContainerOptions) (CloseWaiter, error) {
63
	if opts.Container == "" {
64
		return nil, &NoSuchContainer{ID: opts.Container}
65
	}
66
	path := "/containers/" + opts.Container + "/attach?" + queryString(opts)
67
	return c.hijack(http.MethodPost, path, hijackOptions{
68
		success:        opts.Success,
69
		setRawTerminal: opts.RawTerminal,
70
		in:             opts.InputStream,
71
		stdout:         opts.OutputStream,
72
		stderr:         opts.ErrorStream,
73
	})
74
}
75

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.