Documentation ¶
Index ¶
- type Conn
- func (in *Conn) Close() error
- func (in *Conn) CombinedOutput(ctx context.Context, cmd string, opt ...SessionOption) ([]byte, error)
- func (in *Conn) Output(ctx context.Context, cmd string, opt ...SessionOption) ([]byte, error)
- func (in *Conn) Ping(ctx context.Context, opt ...SessionOption) (err error)
- func (in *Conn) Reset() (err error)
- func (in *Conn) Run(ctx context.Context, cmd string, opt ...SessionOption) error
- func (in *Conn) Start(ctx context.Context, cmd string, opt ...SessionOption) (err error)
- func (in *Conn) Wait() error
- type PtyOption
- type Session
- func (in *Session) Close() error
- func (in *Session) CombinedOutput(ctx context.Context, cmd string) ([]byte, error)
- func (in *Session) Output(ctx context.Context, cmd string) ([]byte, error)
- func (in *Session) Run(ctx context.Context, cmd string) error
- func (in *Session) SetupPty(opt PtyOption) error
- func (in *Session) Start(ctx context.Context, cmd string) (err error)
- func (in *Session) Wait() (err error)
- type SessionOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct { *Session // contains filtered or unexported fields }
Conn indicates an reusable SSH connection.
func NewConn ¶
func NewConn(network, hostport string, cfg *ssh.ClientConfig) (*Conn, error)
NewConn initiates a new connection to hostport on network with given cfg. It returns the new Conn and any encountered error.
func (*Conn) CombinedOutput ¶
func (in *Conn) CombinedOutput(ctx context.Context, cmd string, opt ...SessionOption) ([]byte, error)
CombinedOutput executes a command at foreground, returns a combined output and any encountered error.
func (*Conn) Output ¶
Output executes a command at foreground, returns stdout and any encountered error.
func (*Conn) Ping ¶
func (in *Conn) Ping(ctx context.Context, opt ...SessionOption) (err error)
Ping launches a testing session with given opt if specified, and returns any encountered error.
func (*Conn) Reset ¶
Reset cleanups current session to prepare for next operation. It returns error if encountered any.
type PtyOption ¶
type PtyOption struct { // Term indicates the variant of the terminal. Such as: vt100, xterm, // xterm-256color, etc. Term string // Height indicates the window height. Height int // Width indicates the window width. Width int }
PtyOption is the configuration of current PTY that is used by session.
type Session ¶
type Session struct { // CommandFn is used for constructing command string. If it is not // specified, then will use the raw string directly. CommandFn func(string) string // PostStartFn will be performed after the session is started. Generally, // this is a function that enters password if it is required by some // command like `su`. It is for general purpose. PostStartFn func(*Session) error // Stdin is a piped standard input. Stdin io.WriteCloser // Stdout is a piped standard output. Stdout io.Reader // Stderr is a piped standard error. Stderr io.Reader // contains filtered or unexported fields }
Session is a ssh session wrapper which enables you to do some advanced operations.
func NewSession ¶
NewSession generates Session with sess, and returns any encountered error.
func (*Session) CombinedOutput ¶
CombinedOutput performs given cmd with ctx, and waits until the session finishes. It returns the combined output and encountered error which could be an execution error or the ctx exceeds its deadline or has been cancelled.
func (*Session) Output ¶
Output performs given cmd with ctx, and waits until the session finishes. It returns the standard output and encountered error which could be an execution error or the ctx exceeds its deadline or has been cancelled.
func (*Session) Run ¶
Run performs given cmd with ctx, and waits until the session finishes. It returns err if an execution error has encountered or the ctx exceeds its deadline or has been cancelled.
func (*Session) SetupPty ¶
SetupPty configures the current session pty with given opt, and returns any encountered error. If opt is empty, it will automatically be fulfilled with `vt100`, 60, 80. This is highly recommended to be called before performing operations.
type SessionOption ¶
SessionOption is the extra option while initiating a new SSH session.
func WithSu ¶
func WithSu(username, password string) SessionOption
WithSu generates a new SessionOption with given username and password.
func WithSudo ¶
func WithSudo(password string) SessionOption
WithSudo generates a new SessionOption with given password. Omit password if there is no need to enter password for current user.