Skip to content

Commit

Permalink
🎨 style: format codes, replace interface{} to any
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Jul 1, 2023
1 parent 4c4c4c2 commit e08faea
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion _example/demos/slog_all_level.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func main() {
printAllLevel(l, "this is a", "log", "message")
}

func printAllLevel(l *slog.Logger, args ...interface{}) {
func printAllLevel(l *slog.Logger, args ...any) {
l.Debug(args...)
l.Info(args...)
l.Warn(args...)
Expand Down
4 changes: 2 additions & 2 deletions benchmark2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Test_formatArgsWithSpaces_oneElem_AllocTimes(t *testing.T) {
// output: 1 times -> 0 times
fmt.Println("Alloc Times:", int(testing.AllocsPerRun(10, func() {
// logger.Info("rate", "15", "low", 16, "high", 123.2, msg)
formatArgsWithSpaces([]interface{}{
formatArgsWithSpaces([]any{
"msg", // 2343, -23, 123.2,
})
})))
Expand All @@ -42,7 +42,7 @@ func Test_AllocTimes_formatArgsWithSpaces_manyElem(t *testing.T) {
// `int <0`, `int > 100` will alloc 1 times memory
fmt.Println("Alloc Times:", int(testing.AllocsPerRun(100, func() {
// logger.Info("rate", "15", "low", 16, "high", 123.2, msg)
formatArgsWithSpaces([]interface{}{
formatArgsWithSpaces([]any{
"rate", -23, true, 106, "high", 123.2,
})
})))
Expand Down
10 changes: 5 additions & 5 deletions common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestM_String(t *testing.T) {
"k3": 23.45,
"k4": []int{12, 23},
"k5": []string{"ab", "bc"},
"k6": map[string]interface{}{
"k6": map[string]any{
"k6-1": 23,
"k6-2": "def",
},
Expand Down Expand Up @@ -96,11 +96,11 @@ func newLogRecord(msg string) *slog.Record {
Level: slog.InfoLevel,
Message: msg,
Time: slog.DefaultClockFn.Now(),
Data: map[string]interface{}{
Data: map[string]any{
"data_key0": "value",
"username": "inhere",
},
Extra: map[string]interface{}{
Extra: map[string]any{
"source": "linux",
"extra_key0": "hello",
},
Expand Down Expand Up @@ -194,7 +194,7 @@ func newLogger() *slog.Logger {
})
}

func printAllLevelLogs(l gsr.Logger, args ...interface{}) {
func printAllLevelLogs(l gsr.Logger, args ...any) {
l.Debug(args...)
l.Info(args...)
l.Warn(args...)
Expand All @@ -215,7 +215,7 @@ func printAllLevelLogs(l gsr.Logger, args ...interface{}) {
}
}

func printfAllLevelLogs(l gsr.Logger, tpl string, args ...interface{}) {
func printfAllLevelLogs(l gsr.Logger, tpl string, args ...any) {
l.Printf(tpl, args...)
l.Debugf(tpl, args...)
l.Infof(tpl, args...)
Expand Down
2 changes: 1 addition & 1 deletion formatter_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewTextFormatter(template ...string) *TextFormatter {
TimeFormat: DefaultTimeFormat,
ColorTheme: ColorTheme,
// EnableColor: color.SupportColor(),
// EncodeFunc: func(v interface{}) string {
// EncodeFunc: func(v any) string {
// return fmt.Sprint(v)
// },
EncodeFunc: EncodeToString,
Expand Down
2 changes: 1 addition & 1 deletion handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func newLogRecord(msg string) *slog.Record {
Message: msg,
Time: slog.DefaultClockFn.Now(),
Data: sampleData,
Extra: map[string]interface{}{
Extra: map[string]any{
"source": "linux",
"extra_key0": "hello",
"sub": slog.M{"sub_key1": "val0"},
Expand Down
2 changes: 1 addition & 1 deletion slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func printLogs(msg string) {
slog.ErrorT(errorx.Newf("Traced Err: %s", msg))
}

func printfLogs(msg string, args ...interface{}) {
func printfLogs(msg string, args ...any) {
slog.Printf(msg, args...)
slog.Tracef(msg, args...)
slog.Debugf(msg, args...)
Expand Down

0 comments on commit e08faea

Please sign in to comment.