A deep dive into how Go's `slog.Attr.Equal` method determines equality between log attributes. By examining the source code, it reveals that equality is type-wise first, then value-based. Key behaviors include: custom types (e.g., `myBool`) are not equal to their underlying types, integers across different Go integer types compare as equal, and passing non-comparable values like slices will cause a runtime panic — making it risky to test equality on unknown slog attributes.

2m read timeFrom boldlygo.tech
Post cover image
17.9K Impressions1 Comment