|
| 1 | +package key_naming_case |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "log/slog" |
| 6 | +) |
| 7 | + |
| 8 | +const ( |
| 9 | + snakeKey = "foo_bar" |
| 10 | + kebabKey = "foo-bar" |
| 11 | +) |
| 12 | + |
| 13 | +func _() { |
| 14 | + slog.Info("msg") |
| 15 | + slog.Info("msg", "foo_bar", 1) |
| 16 | + slog.Info("msg", snakeKey, 1) |
| 17 | + slog.Info("msg", slog.Int("foo_bar", 1)) |
| 18 | + slog.Info("msg", slog.Int(snakeKey, 1)) |
| 19 | + slog.Info("msg", slog.Attr{}) |
| 20 | + slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) |
| 21 | + slog.Info("msg", slog.Attr{snakeKey, slog.IntValue(1)}) |
| 22 | + slog.Info("msg", slog.Attr{Key: "foo_bar"}) |
| 23 | + slog.Info("msg", slog.Attr{Key: snakeKey}) |
| 24 | + slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) |
| 25 | + slog.Info("msg", slog.Attr{Key: snakeKey, Value: slog.IntValue(1)}) |
| 26 | + slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) |
| 27 | + slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: snakeKey}) |
| 28 | + |
| 29 | + slog.Info("msg", "foo_bar", 1) // want `keys should be written in snake_case` |
| 30 | + slog.Info("msg", "foo_bar", 1) // want `keys should be written in snake_case` |
| 31 | + slog.Info("msg", slog.Int("foo_bar", 1)) // want `keys should be written in snake_case` |
| 32 | + slog.Info("msg", slog.Int("foo_bar", 1)) // want `keys should be written in snake_case` |
| 33 | + slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) // want `keys should be written in snake_case` |
| 34 | + slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) // want `keys should be written in snake_case` |
| 35 | + slog.Info("msg", slog.Attr{Key: "foo_bar"}) // want `keys should be written in snake_case` |
| 36 | + slog.Info("msg", slog.Attr{Key: "foo_bar"}) // want `keys should be written in snake_case` |
| 37 | + slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) // want `keys should be written in snake_case` |
| 38 | + slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) // want `keys should be written in snake_case` |
| 39 | + slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `keys should be written in snake_case` |
| 40 | + slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `keys should be written in snake_case` |
| 41 | + |
| 42 | + // With snake_case key |
| 43 | + slog.Info("msg") |
| 44 | + slog.With("foo_bar", 1).Info("msg") |
| 45 | + slog.With(snakeKey, 1).Info("msg") |
| 46 | + slog.With(slog.Int("foo_bar", 1)).Info("msg") |
| 47 | + slog.With(slog.Int(snakeKey, 1)).Info("msg") |
| 48 | + slog.With(slog.Attr{}).Info("msg") |
| 49 | + slog.With(slog.Attr{"foo_bar", slog.IntValue(1)}).Info("msg") |
| 50 | + slog.With(slog.Attr{snakeKey, slog.IntValue(1)}).Info("msg") |
| 51 | + slog.With(slog.Attr{Key: "foo_bar"}).Info("msg") |
| 52 | + slog.With(slog.Attr{Key: snakeKey}).Info("msg") |
| 53 | + slog.With(slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}).Info("msg") |
| 54 | + slog.With(slog.Attr{Key: snakeKey, Value: slog.IntValue(1)}).Info("msg") |
| 55 | + slog.With(slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}).Info("msg") |
| 56 | + slog.With(slog.Attr{Value: slog.IntValue(1), Key: snakeKey}).Info("msg") |
| 57 | + |
| 58 | + slog.With("foo_bar", 1).Info("msg") // want `keys should be written in snake_case` |
| 59 | + slog.With("foo_bar", 1).Info("msg") // want `keys should be written in snake_case` |
| 60 | + slog.With(slog.Int("foo_bar", 1)).Info("msg") // want `keys should be written in snake_case` |
| 61 | + slog.With(slog.Int("foo_bar", 1)).Info("msg") // want `keys should be written in snake_case` |
| 62 | + slog.With(slog.Attr{"foo_bar", slog.IntValue(1)}).Info("msg") // want `keys should be written in snake_case` |
| 63 | + slog.With(slog.Attr{"foo_bar", slog.IntValue(1)}).Info("msg") // want `keys should be written in snake_case` |
| 64 | + slog.With(slog.Attr{Key: "foo_bar"}).Info("msg") // want `keys should be written in snake_case` |
| 65 | + slog.With(slog.Attr{Key: "foo_bar"}).Info("msg") // want `keys should be written in snake_case` |
| 66 | + slog.With(slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}).Info("msg") // want `keys should be written in snake_case` |
| 67 | + slog.With(slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}).Info("msg") // want `keys should be written in snake_case` |
| 68 | + slog.With(slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}).Info("msg") // want `keys should be written in snake_case` |
| 69 | + slog.With(slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}).Info("msg") // want `keys should be written in snake_case` |
| 70 | + |
| 71 | + slog.LogAttrs(context.TODO(), slog.LevelInfo, "msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `keys should be written in snake_case` |
| 72 | +} |
| 73 | + |
| 74 | +func issue35() { |
| 75 | + intAttr := slog.Int |
| 76 | + slog.Info("msg", intAttr("foo_bar", 1)) |
| 77 | +} |
0 commit comments