proxy

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrCircuitBreakerOpen is returned when circuit breaker is open
	ErrCircuitBreakerOpen = errors.New("circuit breaker is open")
)

Functions

This section is empty.

Types

type BackendConn

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

BackendConn wraps a backend MySQL connection with metadata

func NewBackendConn

func NewBackendConn(conn net.Conn, connID uint32) *BackendConn

NewBackendConn creates a new backend connection wrapper

func (*BackendConn) Age

func (bc *BackendConn) Age() time.Duration

Age returns the age of the connection

func (*BackendConn) Close

func (bc *BackendConn) Close() error

Close closes the backend connection

func (*BackendConn) Conn

func (bc *BackendConn) Conn() net.Conn

Conn returns the underlying net.Conn

func (*BackendConn) GetDatabase

func (bc *BackendConn) GetDatabase() string

GetDatabase returns the current database context

func (*BackendConn) IdleTime

func (bc *BackendConn) IdleTime() time.Duration

IdleTime returns how long the connection has been idle

func (*BackendConn) IsHealthy

func (bc *BackendConn) IsHealthy() bool

IsHealthy performs a basic health check

func (*BackendConn) IsInTransaction

func (bc *BackendConn) IsInTransaction() bool

IsInTransaction returns whether the connection is in a transaction

func (*BackendConn) Reset

func (bc *BackendConn) Reset() error

Reset resets the connection state for reuse

func (*BackendConn) SetDatabase

func (bc *BackendConn) SetDatabase(db string)

SetDatabase sets the current database context

func (*BackendConn) SetInTransaction

func (bc *BackendConn) SetInTransaction(inTx bool)

SetInTransaction sets the transaction state

func (*BackendConn) UpdateLastUsed

func (bc *BackendConn) UpdateLastUsed()

UpdateLastUsed updates the last used timestamp

type BackendPool

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

BackendPool manages a pool of backend MySQL connections

func NewBackendPool

func NewBackendPool(cfg *config.Config, poolSize int) (*BackendPool, error)

NewBackendPool creates a new backend connection pool

func (*BackendPool) Acquire

func (bp *BackendPool) Acquire() (*BackendConn, error)

Acquire gets a connection from the pool or creates a new one

func (*BackendPool) Close

func (bp *BackendPool) Close() error

Close closes the pool and all connections

func (*BackendPool) Release

func (bp *BackendPool) Release(conn *BackendConn)

Release returns a connection to the pool

func (*BackendPool) Stats

func (bp *BackendPool) Stats() map[string]interface{}

Stats returns pool statistics

type CircuitBreaker

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

CircuitBreaker implements the circuit breaker pattern

func NewCircuitBreaker

func NewCircuitBreaker(config CircuitBreakerConfig) *CircuitBreaker

NewCircuitBreaker creates a new circuit breaker

func (*CircuitBreaker) Call

func (cb *CircuitBreaker) Call(fn func() error) error

Call executes the given function with circuit breaker protection

func (*CircuitBreaker) GetState

func (cb *CircuitBreaker) GetState() CircuitBreakerState

GetState returns the current state (thread-safe)

func (*CircuitBreaker) GetStats

func (cb *CircuitBreaker) GetStats() map[string]interface{}

GetStats returns circuit breaker statistics

func (*CircuitBreaker) IsOpen

func (cb *CircuitBreaker) IsOpen() bool

IsOpen returns true if the circuit is open

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset resets the circuit breaker to closed state

type CircuitBreakerConfig

type CircuitBreakerConfig struct {
	// MaxFailures before opening the circuit
	MaxFailures int
	// Timeout duration to wait before attempting to close an open circuit
	Timeout time.Duration
	// MaxRequests allowed in half-open state
	MaxRequests int
}

CircuitBreakerConfig holds circuit breaker configuration

func DefaultCircuitBreakerConfig

func DefaultCircuitBreakerConfig() CircuitBreakerConfig

DefaultCircuitBreakerConfig returns default configuration

type CircuitBreakerState

type CircuitBreakerState int

CircuitBreakerState represents the state of the circuit breaker

const (
	StateClosed CircuitBreakerState = iota
	StateOpen
	StateHalfOpen
)

func (CircuitBreakerState) String

func (s CircuitBreakerState) String() string

type Server

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

Server represents the proxy server

func NewServer

func NewServer(cfg *config.Config) *Server

NewServer creates a new proxy server

func (*Server) Start

func (s *Server) Start() error

Start starts the proxy server

func (*Server) Stop

func (s *Server) Stop()

Stop stops the proxy server

type Session

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

Session manages a client connection

func NewSession

func NewSession(conn net.Conn, cfg *config.Config, pool *BackendPool) *Session

NewSession creates a new session

func (*Session) Handle

func (s *Session) Handle() error

Handle processes the session

Jump to

Keyboard shortcuts

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