Skip to content

Feature/support slice and map structs#42

Merged
Azhovan merged 2 commits intomainfrom
feature/support-slice-and-map-structs-v3
Feb 23, 2026
Merged

Feature/support slice and map structs#42
Azhovan merged 2 commits intomainfrom
feature/support-slice-and-map-structs-v3

Conversation

@Azhovan
Copy link
Owner

@Azhovan Azhovan commented Feb 23, 2026

What

Add partial nested collection binding support for struct elements/values in the existing load/bind flow:

  • Bind []T where T is a struct from YAML-decoded collection values (for example, []any containing nested objects).
  • Bind map[string]T where T is a struct when the source provides a direct nested map value (for example, in-memory/custom sources returning map[string]any values).
  • Add loader regression tests covering successful binding and invalid nested type conversion (invalid_type) for nested collections.

This PR does not yet support binding map[string]T from flattened dotted keys (for example, clickhouse_map.primary.host) produced by the built-in file source, and does not include strict-mode dynamic nested-key validation for that shape.

Docs: N/A — this change does not alter public APIs, config tags/defaults, examples, or setup/onboarding flow.

Why

Rigging already supports nested struct binding, but nested collections of structs ([]T, map[string]T) were not handled in the binder for direct collection values. This PR delivers a minimal, low-risk improvement while keeping scope small.

Type

  • Fix
  • Feature
  • Docs
  • Performance
  • Breaking change

Partially addresses #33

@Azhovan Azhovan changed the title Feature/support slice and map structs v3 Feature/support slice and map structs Feb 23, 2026
@Azhovan Azhovan requested a review from asadijabar February 23, 2026 16:06
@Azhovan Azhovan self-assigned this Feb 23, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for binding nested collections of structs ([]T and map[string]T where T is a struct) from YAML-decoded configuration values. It enables common configuration patterns like multiple database connections or service endpoints to be defined as slices or maps of structured configuration objects.

Changes:

  • Enhanced convertValue in binding.go to recursively handle slices and maps with struct element/value types
  • Added helper functions convertCollectionElement and convertStructValue to properly bind struct instances within collections
  • Added comprehensive test coverage in loader_test.go for successful binding and error cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
loader_test.go Adds TestLoad_NestedCollections with subtests for binding slices/maps of structs and validating type conversion errors
binding.go Extends convertValue to handle slices/maps of any type including structs, adds convertCollectionElement and convertStructValue helpers for recursive binding

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Azhovan Azhovan review requested due to automatic review settings February 23, 2026 16:26
@Azhovan Azhovan merged commit 83c5f0b into main Feb 23, 2026
9 checks passed
@github-actions github-actions bot deleted the feature/support-slice-and-map-structs-v3 branch February 23, 2026 16:30
@Azhovan Azhovan added the enhancement New feature or request label Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants