utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLogFile = "sql-runner.log"
)

Variables

This section is empty.

Functions

func DecryptPassword added in v1.0.0

func DecryptPassword(encrypted string) (string, error)

DecryptPassword 解密密码

func EncryptPassword added in v1.0.0

func EncryptPassword(password string) (string, error)

EncryptPassword 加密密码

func IsEncrypted added in v1.0.0

func IsEncrypted(password string) bool

IsEncrypted 检查密码是否已加密, 注意: 空密码不是有效密码

Types

type LogEntry

type LogEntry struct {
	Time   time.Time      `json:"time"`
	Level  string         `json:"level"`
	Source *LogSource     `json:"source"`
	Msg    string         `json:"msg"`
	Args   map[string]any `json:"args,omitempty"`
}

LogEntry 表示一条日志记录

type LogLevel

type LogLevel int

LogLevel 日志级别

const (
	LogLevelDebug LogLevel = iota
	LogLevelInfo
	LogLevelWarn
	LogLevelError
)

type LogSource

type LogSource struct {
	Function string `json:"function"`
	File     string `json:"file"`
	Line     int    `json:"line"`
}

LogSource 表示日志来源信息

type Logger

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

Logger 日志记录器

func NewLogger

func NewLogger(logFile string, level string, jsonFormat bool) (*Logger, error)

NewLogger 创建新的日志记录器

func (*Logger) Close

func (l *Logger) Close() error

Close 关闭日志文件

func (*Logger) Debug

func (l *Logger) Debug(msg string, args ...any)

func (*Logger) Error

func (l *Logger) Error(msg string, args ...any)

func (*Logger) Fatal

func (l *Logger) Fatal(msg string, args ...any)

func (*Logger) Info

func (l *Logger) Info(msg string, args ...any)

func (*Logger) Warn

func (l *Logger) Warn(msg string, args ...any)

type Metrics

type Metrics struct {
	StartTime     time.Time
	EndTime       time.Time
	QueryCount    int64
	SuccessCount  int64
	FailureCount  int64
	TotalDuration int64 // 纳秒
}

Metrics 性能指标收集器

func NewMetrics

func NewMetrics() *Metrics

NewMetrics 创建新的指标收集器

func (*Metrics) AddQuery

func (m *Metrics) AddQuery(duration time.Duration, success bool)

AddQuery 添加查询统计

func (*Metrics) AverageDuration

func (m *Metrics) AverageDuration() time.Duration

AverageDuration 获取平均执行时间

func (*Metrics) Duration

func (m *Metrics) Duration() time.Duration

Duration 获取总执行时间

func (*Metrics) End

func (m *Metrics) End()

End 结束收集指标

func (*Metrics) Start

func (m *Metrics) Start()

Start 开始收集指标

func (*Metrics) String

func (m *Metrics) String() string

String 获取指标字符串表示

Jump to

Keyboard shortcuts

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