Help us shape the future of Go! Take the 2026 Go Developer Survey

ssh

package
v0.0.0-...-e511b2b Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrGenerateHostKey

func LoadOrGenerateHostKey(path string) (ssh.Signer, error)

*

  • Loads existing Ed25519 host key or generates a new one if not found.
  • @param path - Filesystem path to store/load the key
  • @return SSH signer for the host key
  • @return error if key operations fail
  • @effects Creates key file on disk if it doesn't exist

func StartServer

func StartServer(cfg *Config) error

*

  • Starts the SSH server and begins accepting connections.
  • @param cfg - Server configuration (port, password, keys)
  • @return error if server fails to start or crashes
  • @effects Blocks current goroutine until server stops

Types

type Config

type Config struct {
	Port         int
	HostKeyPath  string
	MaxPerMinute int // Rate limit: connections per minute per IP
}

*

  • Server configuration loaded from environment variables.

func LoadConfig

func LoadConfig() *Config

*

  • Loads server configuration from environment variables with defaults.
  • @return Config populated with values from env or defaults

type RateLimiter

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

*

  • Rate limiter that tracks connection attempts per IP address.

func NewRateLimiter

func NewRateLimiter(requestsPerMinute int) *RateLimiter

*

  • Creates a new rate limiter with specified requests per minute.
  • @param requestsPerMinute - Maximum requests allowed per minute per IP
  • @return Configured RateLimiter instance

func (*RateLimiter) Allow

func (rl *RateLimiter) Allow(ip string) bool

*

  • Checks if a connection from the given IP should be allowed.
  • @param ip - IP address to check
  • @return true if connection is allowed, false if rate limited
  • @effects Updates internal rate limit state for the IP

func (*RateLimiter) CleanupOldLimiters

func (rl *RateLimiter) CleanupOldLimiters()

*

  • Cleans up old limiters to prevent memory leaks.
  • Should be called periodically in a goroutine.
  • @effects Removes inactive IP entries from the limiter map

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL