server

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 24, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionBinding

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

ConnectionBinding tracks handshake state for one MySQL connection. go-mysql may call UseDB before authentication completes, so binding is finalized only after a successful handshake.

func (*ConnectionBinding) Database

func (b *ConnectionBinding) Database() *storage.Database

Database returns the finalized database, if any.

func (*ConnectionBinding) Finalize

func (b *ConnectionBinding) Finalize(username string) (*storage.Database, error)

Finalize permanently binds the connection to the authenticated database.

func (*ConnectionBinding) RequestedDB

func (b *ConnectionBinding) RequestedDB() string

RequestedDB returns the database name requested during handshake, if any.

func (*ConnectionBinding) SetCandidate

func (b *ConnectionBinding) SetCandidate(db *storage.Database)

SetCandidate stores the authenticated database for later finalization.

func (*ConnectionBinding) SetRequestedDB

func (b *ConnectionBinding) SetRequestedDB(name string) error

SetRequestedDB records the database name from the handshake or COM_INIT_DB. Before finalization this only stores a request; after finalization it enforces immutable binding.

type CredentialProvider

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

CredentialProvider implements server.CredentialProvider using the storage registry.

func NewCredentialProvider

func NewCredentialProvider(store *storage.Store, binding *ConnectionBinding) *CredentialProvider

NewCredentialProvider creates a per-connection credential provider.

func (*CredentialProvider) CheckUsername

func (p *CredentialProvider) CheckUsername(username string) (bool, error)

CheckUsername reports whether the username exists.

func (*CredentialProvider) GetCredential

func (p *CredentialProvider) GetCredential(username string) (password string, found bool, err error)

GetCredential returns the password for username and stages the database candidate. Username/database mismatches intentionally look like authentication failures.

type HandlerFactory

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

HandlerFactory creates per-session MySQL protocol handlers.

func NewHandlerFactory

func NewHandlerFactory() *HandlerFactory

NewHandlerFactory creates a factory for session-scoped handlers.

func (*HandlerFactory) NewSessionHandler

func (f *HandlerFactory) NewSessionHandler(session *Session, binding *ConnectionBinding) *SessionHandler

NewSessionHandler returns a handler bound to a client session and connection binding.

type Session

type Session struct {
	ID           string
	Username     string
	Database     string
	ConnectedAt  time.Time
	LastActiveAt time.Time
	Variables    map[string]string

	// Bound tenant database (immutable after auth)
	BoundDB *storage.Database

	// Transaction state
	InTransaction bool
	Tx            *sql.Tx

	// Per-session database connection for coherency
	DB *sql.Conn
	// contains filtered or unexported fields
}

Session represents a client connection session

func NewSession

func NewSession(id string) *Session

NewSession creates a new unbound session

func (*Session) BeginTransaction

func (s *Session) BeginTransaction(tx *sql.Tx)

BeginTransaction starts a transaction on this session

func (*Session) Bind

func (s *Session) Bind(db *storage.Database) error

Bind permanently attaches the session to an authenticated database.

func (*Session) Close

func (s *Session) Close() error

Close cleans up session resources

func (*Session) CommitTransaction

func (s *Session) CommitTransaction() error

CommitTransaction commits the current transaction

func (*Session) GetBoundDB

func (s *Session) GetBoundDB() *storage.Database

GetBoundDB returns the authenticated tenant database.

func (*Session) GetConnection

func (s *Session) GetConnection() *sql.Conn

GetConnection returns the per-session database connection

func (*Session) GetDatabase

func (s *Session) GetDatabase() string

GetDatabase returns the current database

func (*Session) GetTransaction

func (s *Session) GetTransaction() *sql.Tx

GetTransaction returns the current transaction

func (*Session) GetVariable

func (s *Session) GetVariable(key string) (string, bool)

GetVariable gets a session variable

func (*Session) IsInTransaction

func (s *Session) IsInTransaction() bool

IsInTransaction returns whether the session is in a transaction

func (*Session) RollbackTransaction

func (s *Session) RollbackTransaction() error

RollbackTransaction rolls back the current transaction

func (*Session) SetConnection

func (s *Session) SetConnection(conn *sql.Conn)

SetConnection sets the per-session database connection

func (*Session) SetDatabase

func (s *Session) SetDatabase(db string)

SetDatabase sets the current database name label (must match bound DB).

func (*Session) SetVariable

func (s *Session) SetVariable(key, value string)

SetVariable sets a session variable

type SessionHandler

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

SessionHandler implements server.Handler for a single client connection.

func (*SessionHandler) Finalize

func (h *SessionHandler) Finalize(username string) error

Finalize binds the handler to the authenticated database after handshake.

func (*SessionHandler) HandleFieldList

func (h *SessionHandler) HandleFieldList(table string, fieldWildcard string) ([]*mysql.Field, error)

HandleFieldList handles COM_FIELD_LIST command.

func (*SessionHandler) HandleOtherCommand

func (h *SessionHandler) HandleOtherCommand(cmd byte, data []byte) error

HandleOtherCommand handles other MySQL commands.

func (*SessionHandler) HandleQuery

func (h *SessionHandler) HandleQuery(query string) (*mysql.Result, error)

HandleQuery handles COM_QUERY commands (text protocol).

func (*SessionHandler) HandleStmtClose

func (h *SessionHandler) HandleStmtClose(context interface{}) error

HandleStmtClose handles COM_STMT_CLOSE.

func (*SessionHandler) HandleStmtExecute

func (h *SessionHandler) HandleStmtExecute(context interface{}, query string, args []interface{}) (*mysql.Result, error)

HandleStmtExecute handles COM_STMT_EXECUTE.

func (*SessionHandler) HandleStmtPrepare

func (h *SessionHandler) HandleStmtPrepare(query string) (int, int, interface{}, error)

HandleStmtPrepare handles COM_STMT_PREPARE.

func (*SessionHandler) UseDB

func (h *SessionHandler) UseDB(dbName string) error

UseDB handles COM_INIT_DB command (database selection).

type SessionManager

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

SessionManager manages active sessions

func NewSessionManager

func NewSessionManager() *SessionManager

NewSessionManager creates a new session manager

func (*SessionManager) Cleanup

func (sm *SessionManager) Cleanup(maxInactive time.Duration) int

Cleanup removes inactive sessions

func (*SessionManager) Count

func (sm *SessionManager) Count() int

Count returns the number of active sessions

func (*SessionManager) Create

func (sm *SessionManager) Create(id string) *Session

Create creates a new unbound session

func (*SessionManager) Get

func (sm *SessionManager) Get(id string) (*Session, bool)

Get returns a session by ID

func (*SessionManager) Remove

func (sm *SessionManager) Remove(id string)

Remove removes a session

Jump to

Keyboard shortcuts

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