elastic / elastic/fleet-server

config InitDefaults

Open
#3,090 0 comments 0 reactions 0 assignees View on GitHub
Team:Fleet tech debt
Dominant language
Go
Stars
113
Forks
117
Avg merge
1d 16h
Merged PRs (30d)
112

Description

go-ucfg's [`Unpack`](https://pkg.go.dev/github.com/elastic/go-ucfg#Config.Unpack) method calls `InitDefaults` on the passed item along with any of it's children that implement the function.

However we explicity call the children's `InitDefaults` from the parent:
https://github.com/elastic/fleet-server/blob/0718a55b3152a902f3c47bb841afa78cb166231b/internal/pkg/config/input.go#L155-L160
and this continues for a few extra layers:
https://github.com/elastic/fleet-server/blob/0718a55b3152a902f3c47bb841afa78cb166231b/internal/pkg/config/input.go#L96-L109

These extra `InitDefaults` calls are not needed; the input's `InitDefaults` can probably be reduced to
```go
func (c *Input) InitDefaults() {
c.Type = fleetInputType
}
```
and most other structs in our config package can be redone as well.
We should try to clean this up to reduce extra calls.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.