Skip to content

Commit 9d35256

Browse files
committed
Address review feedback: remove changelog, add squash tag docs
- Remove changelog entry (not needed for doc-only changes per dmathieu) - Add documentation about using squash tag with named fields to achieve flat YAML structure while avoiding true embedding (per evan-bradley)
1 parent e472a0d commit 9d35256

File tree

2 files changed

+13
-27
lines changed

2 files changed

+13
-27
lines changed

.chloggen/docs_avoid-embedded-structs-in-configs.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/coding-guidelines.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ type ExporterConfig struct {
102102

103103
This practice ensures better maintainability and prevents subtle bugs related to struct composition and configuration unmarshaling.
104104

105+
**Preserving Flat YAML Structure with the `squash` Tag:**
106+
107+
In some cases, you may need to maintain backward compatibility with an existing flat YAML configuration structure while still using named fields in Go. The `mapstructure:",squash"` tag achieves this by flattening the nested struct's fields into the parent configuration:
108+
109+
```go
110+
// Using named fields with squash tag for flat YAML structure
111+
type Config struct {
112+
ClientConfig confighttp.ClientConfig `mapstructure:",squash"`
113+
}
114+
```
115+
116+
This allows the YAML configuration to remain flat (fields at the top level) while the Go code uses a named field. However, prefer explicitly nested configurations (without `squash`) for new components, as the nested structure is clearer and avoids the issues mentioned above.
117+
105118
## Module organization
106119

107120
As usual in Go projects, organize your code into packages grouping related functionality. To ensure

0 commit comments

Comments
 (0)