Skip to content

Commit 033194d

Browse files
committed
refactor: replace interface{} types with any in multiple files
- Update logger method arguments from `interface{}` to `any` - Change panic channel type in queue handling from `interface{}` to `any` - Modify `New` function in buffer pool from `interface{}` to `any` Signed-off-by: appleboy <appleboy.tw@gmail.com>
1 parent 6ada93f commit 033194d

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

logger.go

+20-20
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88

99
// Logger interface is used throughout gorush
1010
type Logger interface {
11-
Infof(format string, args ...interface{})
12-
Errorf(format string, args ...interface{})
13-
Fatalf(format string, args ...interface{})
14-
Info(args ...interface{})
15-
Error(args ...interface{})
16-
Fatal(args ...interface{})
11+
Infof(format string, args ...any)
12+
Errorf(format string, args ...any)
13+
Fatalf(format string, args ...any)
14+
Info(args ...any)
15+
Error(args ...any)
16+
Fatal(args ...any)
1717
}
1818

1919
// NewLogger for simple logger.
@@ -31,37 +31,37 @@ type defaultLogger struct {
3131
fatalLogger *log.Logger
3232
}
3333

34-
func (l defaultLogger) logWithCallerf(logger *log.Logger, format string, args ...interface{}) {
34+
func (l defaultLogger) logWithCallerf(logger *log.Logger, format string, args ...any) {
3535
stack := stack(3)
3636
logger.Printf("%s%s", stack, fmt.Sprintf(format, args...))
3737
}
3838

39-
func (l defaultLogger) logWithCaller(logger *log.Logger, args ...interface{}) {
39+
func (l defaultLogger) logWithCaller(logger *log.Logger, args ...any) {
4040
stack := stack(3)
4141
logger.Println(stack, fmt.Sprint(args...))
4242
}
4343

44-
func (l defaultLogger) Infof(format string, args ...interface{}) {
44+
func (l defaultLogger) Infof(format string, args ...any) {
4545
l.infoLogger.Printf(format, args...)
4646
}
4747

48-
func (l defaultLogger) Errorf(format string, args ...interface{}) {
48+
func (l defaultLogger) Errorf(format string, args ...any) {
4949
l.errorLogger.Printf(format, args...)
5050
}
5151

52-
func (l defaultLogger) Fatalf(format string, args ...interface{}) {
52+
func (l defaultLogger) Fatalf(format string, args ...any) {
5353
l.logWithCallerf(l.fatalLogger, format, args...)
5454
}
5555

56-
func (l defaultLogger) Info(args ...interface{}) {
56+
func (l defaultLogger) Info(args ...any) {
5757
l.infoLogger.Println(fmt.Sprint(args...))
5858
}
5959

60-
func (l defaultLogger) Error(args ...interface{}) {
60+
func (l defaultLogger) Error(args ...any) {
6161
l.errorLogger.Println(fmt.Sprint(args...))
6262
}
6363

64-
func (l defaultLogger) Fatal(args ...interface{}) {
64+
func (l defaultLogger) Fatal(args ...any) {
6565
l.logWithCaller(l.fatalLogger, args...)
6666
}
6767

@@ -73,9 +73,9 @@ func NewEmptyLogger() Logger {
7373
// EmptyLogger no meesgae logger
7474
type emptyLogger struct{}
7575

76-
func (l emptyLogger) Infof(format string, args ...interface{}) {}
77-
func (l emptyLogger) Errorf(format string, args ...interface{}) {}
78-
func (l emptyLogger) Fatalf(format string, args ...interface{}) {}
79-
func (l emptyLogger) Info(args ...interface{}) {}
80-
func (l emptyLogger) Error(args ...interface{}) {}
81-
func (l emptyLogger) Fatal(args ...interface{}) {}
76+
func (l emptyLogger) Infof(format string, args ...any) {}
77+
func (l emptyLogger) Errorf(format string, args ...any) {}
78+
func (l emptyLogger) Fatalf(format string, args ...any) {}
79+
func (l emptyLogger) Info(args ...any) {}
80+
func (l emptyLogger) Error(args ...any) {}
81+
func (l emptyLogger) Fatal(args ...any) {}

queue.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func (q *Queue) run(task core.TaskMessage) error {
193193
func (q *Queue) handle(m *job.Message) error {
194194
// create channel with buffer size 1 to avoid goroutine leak
195195
done := make(chan error, 1)
196-
panicChan := make(chan interface{}, 1)
196+
panicChan := make(chan any, 1)
197197
startTime := time.Now()
198198
ctx, cancel := context.WithTimeout(context.Background(), m.Timeout)
199199
defer func() {

recovery.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
// When a buffer is no longer needed, it should be put back into the pool to be
2424
// reused.
2525
var bufferPool = sync.Pool{
26-
New: func() interface{} {
26+
New: func() any {
2727
return new(bytes.Buffer)
2828
},
2929
}

0 commit comments

Comments
 (0)