Add map[string]T support for config fields #7

Closed
opened 2026-09-20 15:05:03 +00:00 by agent · 0 comments
Member

Problem

Config fields of type map[string]string, map[string]int, etc. are silently ignored during load and write. This is a common config pattern (custom labels, env maps, feature flags).

Currently, tag.go only inspects struct fields for the conf tag. Maps are not handled in:

  • load.go loadFromPath — shadow type builder doesn't handle maps
  • write.go buildMarshalOutput / toMarshalValue — maps go through v.Interface() but without proper key mapping
  • env.go — no map support

Requirements

  1. Loading: map[string]string fields should decode from TOML tables, YAML maps, and JSON objects
  2. Writing: map[string]T fields should be serialized back to the correct format
  3. Env vars: Not needed for maps (env var overlay doesn't make sense for map keys)
  4. Conf tags: Maps should use the field's conf:"name" as the key in the config file

Example

type AppConfig struct {
    Labels map[string]string `conf:"labels"`
}
[labels]
environment = "production"
team = "platform"

Scope

  • core/tag.go — shadow type builder needs to handle reflect.Map
  • core/load.go — loadFromPath / copyStructFields need map copy support
  • core/write.go — toMarshalValue / structToMap need map handling
  • Tests for round-trip, nested maps, empty maps

Verification

go test -run TestMap ./...
go test -run TestMap ./... -count=1
## Problem Config fields of type `map[string]string`, `map[string]int`, etc. are silently ignored during load and write. This is a common config pattern (custom labels, env maps, feature flags). Currently, `tag.go` only inspects struct fields for the `conf` tag. Maps are not handled in: - `load.go` `loadFromPath` — shadow type builder doesn't handle maps - `write.go` `buildMarshalOutput` / `toMarshalValue` — maps go through `v.Interface()` but without proper key mapping - `env.go` — no map support ## Requirements 1. **Loading**: `map[string]string` fields should decode from TOML tables, YAML maps, and JSON objects 2. **Writing**: `map[string]T` fields should be serialized back to the correct format 3. **Env vars**: Not needed for maps (env var overlay doesn't make sense for map keys) 4. **Conf tags**: Maps should use the field's `conf:"name"` as the key in the config file ## Example ```go type AppConfig struct { Labels map[string]string `conf:"labels"` } ``` ```toml [labels] environment = "production" team = "platform" ``` ## Scope - `core/tag.go` — shadow type builder needs to handle `reflect.Map` - `core/load.go` — `loadFromPath` / `copyStructFields` need map copy support - `core/write.go` — `toMarshalValue` / `structToMap` need map handling - Tests for round-trip, nested maps, empty maps ## Verification ```bash go test -run TestMap ./... go test -run TestMap ./... -count=1 ```
agent closed this issue 2026-09-20 15:49:32 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
residual/config#7
No description provided.