mysqlproxy

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2025 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDebug added in v0.0.5

func CopyDebug(prefix string, dst io.Writer, src io.Reader) (int64, error)

CopyDebug は io.Copy 相当のヘルパー。 dst 側に DebugWriter をかませてプレフィックス付きダンプを行う。

func DumpResult added in v0.0.5

func DumpResult(res *mysql.Result, err error)

func PrintCapability added in v0.0.5

func PrintCapability(capability uint32)

Types

type ClientSess

type ClientSess struct {
	ClientMysql    *server.Conn
	TargetMysql    *client.Conn
	ProxySrv       *ProxySrv
	TargetNet      string
	TargetAddr     string
	TargetUser     string
	TargetPassword string
	TargetDB       string
}

func (*ClientSess) ConnectToMySQL

func (c *ClientSess) ConnectToMySQL(ctx context.Context) error

ClntSess methods ConnectToMySQL connect to mysql target server

func (*ClientSess) Proxy

func (c *ClientSess) Proxy(ctx context.Context)

type ConfigProvider

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

implements a in memory credential provider

func NewConfigProvider

func NewConfigProvider(m userManager) *ConfigProvider

func (*ConfigProvider) CheckUsername

func (m *ConfigProvider) CheckUsername(username string) (bool, error)

func (*ConfigProvider) GetCredential

func (m *ConfigProvider) GetCredential(username string) (password string, found bool, err error)

type Conn added in v0.0.5

type Conn interface {
	net.Conn
	SetReadDeadline(t time.Time) error  // go-mysql 側で呼ばれることが多いので proxy
	SetWriteDeadline(t time.Time) error // 同上
}

type DebugConn added in v0.0.5

type DebugConn struct {
	Conn   Conn
	Prefix string
	// contains filtered or unexported fields
}

DebugConn は書き込みデバッグ用の薄いラッパ。

func WrapConn added in v0.0.5

func WrapConn(c Conn, prefix string) *DebugConn

WrapConn で包むだけで OK。

func (*DebugConn) Close added in v0.0.5

func (d *DebugConn) Close() error

以下は net.Conn の他メソッドを素通し

func (*DebugConn) LocalAddr added in v0.0.5

func (d *DebugConn) LocalAddr() net.Addr

func (*DebugConn) Read added in v0.0.5

func (d *DebugConn) Read(b []byte) (int, error)

func (*DebugConn) RemoteAddr added in v0.0.5

func (d *DebugConn) RemoteAddr() net.Addr

func (*DebugConn) SetDeadline added in v0.0.5

func (d *DebugConn) SetDeadline(t time.Time) error

func (*DebugConn) SetReadDeadline added in v0.0.5

func (d *DebugConn) SetReadDeadline(t time.Time) error

func (*DebugConn) SetWriteDeadline added in v0.0.5

func (d *DebugConn) SetWriteDeadline(t time.Time) error

func (*DebugConn) Write added in v0.0.5

func (d *DebugConn) Write(b []byte) (int, error)

type DebugWriter added in v0.0.5

type DebugWriter struct {
	W      io.Writer // 実際に書き込む先
	Prefix string    // 行頭に付けるプレフィックス(例: "clientWrite:")
	// contains filtered or unexported fields
}

func (*DebugWriter) Write added in v0.0.5

func (d *DebugWriter) Write(p []byte) (int, error)

Write implements io.Writer.

type LogWriter

type LogWriter interface {
	PushToLogChannel(ctx context.Context, sp *sendpacket.SendPacket) error
	PutSendPacket(b *sendpacket.SendPacket)
	GetSendPacket() *sendpacket.SendPacket
	CloseChannel()
}

type Provider

type Provider ConfigProvider

type ProxyCfg

type ProxyCfg struct {
	ProxyListenAddr string        `default:":3307"` // "localhost:3307"
	ProxyListentNet string        `default:"tcp"`   // tcp or unix
	ConTimeout      time.Duration `default:"300s"`
	LogFileName     string        `default:"mysql-audit.%Y%m%d%H.log.gz"`
	RotateTime      time.Duration `default:"1h"`
	AdminUser       string        `default:"admin"`
	Debug           bool          `default:"false"`
}

type ProxySrv

type ProxySrv struct {
	AuditLogWriter LogWriter
	SvConfMng      *serverconfig.Manager
	Config         *ProxyCfg
	// contains filtered or unexported fields
}

ProxySrv is the main struct for the proxy server

func (*ProxySrv) Start

func (p *ProxySrv) Start(ctx context.Context) error

type ProxyUser

type ProxyUser struct {
	Username string
	Password string
}

type SendTask

type SendTask struct {
	Reader net.Conn
	Writer io.Writer
	User   string
	DB     string
	Addr   string
	ConnID uint32
	Config *ProxyCfg
	LogWriter
}

func (*SendTask) Worker

func (st *SendTask) Worker(ctx context.Context) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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