ptysession

package
v0.0.0-...-d36f2d7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 6, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsUser

func AsUser(username string) options.Option

AsUser sets the username for the session

func WithID

func WithID(id string) options.Option

WithID sets a custom ID for the session

func WithShell

func WithShell(shell string) options.Option

WithShell sets the shell for the session

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager handles concurrent access to PTY sessions

func GetManager

func GetManager() *Manager

GetManager returns the singleton instance of the session manager. It initializes the manager on first call using sync.Once.

func (*Manager) AddSession

func (m *Manager) AddSession(session *Session)

AddSession adds a new PTY session to the manager. It acquires a write lock to safely add the session to the map.

func (*Manager) GetSession

func (m *Manager) GetSession(id string) (*Session, bool)

GetSession retrieves a session by its ID. It returns the session and a boolean indicating if it exists. Uses a read lock since it doesn't modify the sessions map.

func (*Manager) ListSessions

func (m *Manager) ListSessions() []string

ListSessions returns a list of active session IDs. It acquires a read lock since it only reads from the sessions map. Returns a slice containing all session IDs.

func (*Manager) RemoveSession

func (m *Manager) RemoveSession(id string)

RemoveSession removes a session from the manager. It acquires a write lock to safely delete the session from the map.

func (*Manager) StartSessionCleaner

func (m *Manager) StartSessionCleaner(timeout time.Duration)

type Session

type Session struct {
	ID           string
	Stdin        chan []byte
	Stdout       chan []byte
	Pty          *os.File
	Cmd          *exec.Cmd
	Ctx          context.Context
	CancelFunc   context.CancelFunc
	LastActivity time.Time
	CreatedAt    time.Time
}

func StartSession

func StartSession(opts ...options.Option) (*Session, error)

func (*Session) HandleIO

func (s *Session) HandleIO()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳