resolveAttr writes attr into data.
(data map[string]any, attr slog.Attr)
| 228 | |
| 229 | // resolveAttr writes attr into data. |
| 230 | func (h *BatchHandler) resolveAttr(data map[string]any, attr slog.Attr) error { |
| 231 | // ensure that the attr value is resolved before doing anything else |
| 232 | attr.Value = attr.Value.Resolve() |
| 233 | |
| 234 | if attr.Equal(slog.Attr{}) { |
| 235 | return nil // ignore empty attrs |
| 236 | } |
| 237 | |
| 238 | switch attr.Value.Kind() { |
| 239 | case slog.KindGroup: |
| 240 | attrs := attr.Value.Group() |
| 241 | if len(attrs) == 0 { |
| 242 | return nil // ignore empty groups |
| 243 | } |
| 244 | |
| 245 | // create a submap to wrap the resolved group attributes |
| 246 | groupData := make(map[string]any, len(attrs)) |
| 247 | |
| 248 | for _, subAttr := range attrs { |
| 249 | h.resolveAttr(groupData, subAttr) |
| 250 | } |
| 251 | |
| 252 | if len(groupData) > 0 { |
| 253 | data[attr.Key] = groupData |
| 254 | } |
| 255 | default: |
| 256 | data[attr.Key] = normalizeLogAttrValue(attr.Value.Any()) |
| 257 | } |
| 258 | |
| 259 | return nil |
| 260 | } |
| 261 | |
| 262 | func normalizeLogAttrValue(rawAttrValue any) any { |
| 263 | switch attrV := rawAttrValue.(type) { |