recorder

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RecordingStatusActive    = proxy.RecordingStatusActive
	RecordingStatusRecording = proxy.RecordingStatusRecording
	RecordingStatusPaused    = proxy.RecordingStatusPaused
	RecordingStatusStopped   = proxy.RecordingStatusStopped
)

Variables

This section is empty.

Functions

func IsTransactionCommand

func IsTransactionCommand(sql string) (bool, string)

IsTransactionCommand 判断是否是事务命令

Types

type MySQLQuery

type MySQLQuery struct {
	Timestamp    float64 `json:"timestamp"`               // 相对时间(秒)
	SQL          string  `json:"sql"`                     // SQL 语句
	RiskLevel    string  `json:"risk_level"`              // 风险级别
	Blocked      bool    `json:"blocked"`                 // 是否被阻断
	Result       string  `json:"result"`                  // 执行结果
	Duration     float64 `json:"duration,omitempty"`      // 执行耗时(毫秒)
	RowsAffected int64   `json:"rows_affected,omitempty"` // 影响行数
	Error        string  `json:"error,omitempty"`         // 错误信息
}

MySQLQuery MySQL 查询记录

type MySQLRecorder

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

MySQLRecorder MySQL 录制器(JSON 格式)

func NewMySQLRecorder

func NewMySQLRecorder(storage audit.ObjectStorage) *MySQLRecorder

NewMySQLRecorder 创建 MySQL 录制器

func (*MySQLRecorder) GetCurrentDatabase

func (r *MySQLRecorder) GetCurrentDatabase() string

GetCurrentDatabase 获取当前数据库

func (*MySQLRecorder) GetQueries

func (r *MySQLRecorder) GetQueries() []*MySQLQuery

GetQueries 获取所有查询记录

func (*MySQLRecorder) GetQueryCount

func (r *MySQLRecorder) GetQueryCount() int

GetQueryCount 获取查询数量

func (*MySQLRecorder) Protocol

func (r *MySQLRecorder) Protocol() audit.Protocol

Protocol 返回协议类型

func (*MySQLRecorder) RecordQuery

func (r *MySQLRecorder) RecordQuery(timestamp float64, sql string, riskLevel string, blocked bool) error

RecordQuery 记录 SQL 查询

func (*MySQLRecorder) RecordTransactionEnd

func (r *MySQLRecorder) RecordTransactionEnd(timestamp float64, txType string) error

RecordTransactionEnd 记录事务结束

func (*MySQLRecorder) RecordTransactionStart

func (r *MySQLRecorder) RecordTransactionStart(timestamp float64) error

RecordTransactionStart 记录事务开始

func (*MySQLRecorder) SetCurrentDatabase

func (r *MySQLRecorder) SetCurrentDatabase(database string)

SetCurrentDatabase 设置当前数据库(追踪 USE database 命令)

func (*MySQLRecorder) Start

func (r *MySQLRecorder) Start(ctx context.Context, sessionID string, metadata map[string]interface{}) error

Start 开始录制

func (*MySQLRecorder) Status

func (r *MySQLRecorder) Status() RecordingStatus

Status 获取录制状态

func (*MySQLRecorder) Stop

func (r *MySQLRecorder) Stop(ctx context.Context) (string, error)

Stop 停止录制

func (*MySQLRecorder) UpdateQueryResult

func (r *MySQLRecorder) UpdateQueryResult(queryIndex int, result string, duration float64, rowsAffected int64, err error) error

UpdateQueryResult 更新查询结果

func (*MySQLRecorder) Write

func (r *MySQLRecorder) Write(timestamp float64, ioType rune, data []byte) error

Write 实现 Recorder 接口(用于统一录制接口)

type MySQLRecordingMetadata

type MySQLRecordingMetadata struct {
	Version   int           `json:"version"`
	SessionID string        `json:"session_id"`
	StartTime time.Time     `json:"start_time"`
	Database  string        `json:"database,omitempty"`
	User      string        `json:"user,omitempty"`
	Queries   []*MySQLQuery `json:"queries"`
}

MySQLRecordingMetadata MySQL 录制元数据

type Recorder

type Recorder = proxy.Recorder

type RecorderFactory

type RecorderFactory = proxy.RecorderFactory

type RecordingStatus

type RecordingStatus = proxy.RecordingStatus

从 proxy 包导入公共类型和接口

Jump to

Keyboard shortcuts

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