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

mysqlproxy

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package mysqlproxy serves an app's mysql.sock. It speaks just enough of the MySQL protocol to greet the app without asking for credentials, log in upstream as the app's own database user, and relay the session through a command allow-list. Runners import it; apps do not.

Index

Constants

View Source
const MaxConns = 32

MaxConns is how many database connections one app may have open through its proxy.

Variables

This section is empty.

Functions

This section is empty.

Types

type Proxy

type Proxy struct {
	// OnError, if set, gets the reason the proxy could not open the app's database. Errors
	// never carry the password. It may be called from several goroutines at once.
	OnError func(error)
	// contains filtered or unexported fields
}

Proxy serves one app's mysql.sock. It greets the app without asking for credentials, logs in upstream as the app's own database user and relays the session.

func New

func New(up Upstream) *Proxy

New returns a proxy that logs in as up.

func (*Proxy) Close

func (p *Proxy) Close()

Close ends every open session and waits for them to stop. Close the listener first.

func (*Proxy) Serve

func (p *Proxy) Serve(l net.Listener) error

Serve accepts the app's connections on l until l is closed. A connection over MaxConns gets E-SQL-004 and is closed.

func (*Proxy) SetUpstream

func (p *Proxy) SetUpstream(up Upstream)

SetUpstream makes the proxy log in as up from the next connection it accepts on. Sessions already open keep the login they have.

type Upstream

type Upstream struct {
	Network, Address         string
	User, Password, Database string
}

Upstream is where the proxy opens the app's database sessions: the server and the app's own user, password and database.

Jump to

Keyboard shortcuts

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