mirror of
https://github.com/tiny-craft/tiny-rdm.git
synced 2025-10-07 08:01:28 +08:00
feat: add app launch log page
This commit is contained in:
@@ -7,31 +7,41 @@ import (
|
||||
"net"
|
||||
)
|
||||
|
||||
type execCallback func(string)
|
||||
|
||||
type LogHook struct {
|
||||
name string
|
||||
name string
|
||||
cmdExec execCallback
|
||||
}
|
||||
|
||||
func NewHook(name string) LogHook {
|
||||
return LogHook{
|
||||
name: name,
|
||||
func NewHook(name string, cmdExec execCallback) *LogHook {
|
||||
return &LogHook{
|
||||
name: name,
|
||||
cmdExec: cmdExec,
|
||||
}
|
||||
}
|
||||
|
||||
func (LogHook) DialHook(next redis.DialHook) redis.DialHook {
|
||||
func (l *LogHook) DialHook(next redis.DialHook) redis.DialHook {
|
||||
return func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
return next(ctx, network, addr)
|
||||
}
|
||||
}
|
||||
func (LogHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
||||
func (l *LogHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
|
||||
return func(ctx context.Context, cmd redis.Cmder) error {
|
||||
log.Println(cmd.String())
|
||||
log.Println(cmd)
|
||||
if l.cmdExec != nil {
|
||||
l.cmdExec(cmd.String())
|
||||
}
|
||||
return next(ctx, cmd)
|
||||
}
|
||||
}
|
||||
func (LogHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
||||
func (l *LogHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.ProcessPipelineHook {
|
||||
return func(ctx context.Context, cmds []redis.Cmder) error {
|
||||
for _, cmd := range cmds {
|
||||
log.Println(cmd.String())
|
||||
log.Println("pipeline: ", cmd)
|
||||
if l.cmdExec != nil {
|
||||
l.cmdExec(cmd.String())
|
||||
}
|
||||
}
|
||||
return next(ctx, cmds)
|
||||
}
|
||||
|
Reference in New Issue
Block a user