Six mechanical fixes from `golangci-lint run ./...` (30 findings total, 23
deliberately left -- see the next commit's message for the one that grew
into something bigger, and the following note for the rest):
- apply.go: %v -> %w for the wrapped yaml error, matching the identical
double-%w pattern already used in decode.go/discovery.go/loader.go in the
same package (errorlint).
- contract_test.go: filepath.Join("provider.go") with a single argument is a
no-op join; replaced with the literal (gocritic).
- inprocess_test.go, yaegi_test.go: two goroutines whose whole purpose is
timing (does Execute return promptly on cancellation / does Run block
forever), where the call's result is irrelevant -- explicitly discarded
with `_, _ =` and a comment saying why, rather than silently ignored
(errcheck).
- find_test.go: an unchecked os.MkdirAll now matches the file's own
createTestFile helper, which already checks and t.Fatals on the same
operation (errcheck).
Not touched, and why: 18 cyclop/gocognit/gocyclo/funlen/nestif findings
require extracting helpers to reduce complexity -- the exact shape of two
regressions already recorded in CLAUDE.md's Lint-driven changes section
(one from --fix silently dropping a predicate, one from a nestif extraction
that doubled data), so a blind sweep across 9 unfamiliar files was declined
rather than risk a third. 2 godox findings (storage.go, worktree.go) mark
real missing work; deleting the comment would hide debt, not fix it. 3
recvcheck findings (Duration, TaskEnvelope, Provenance) each mix a
mandatory-pointer-receiver method (UnmarshalText/UnmarshalJSON's interface
contract, or genuine mutation) with correctly-value-receiver read-only
methods -- forcing consistency would either break interface conformance or
force pointer receivers onto call sites where the value isn't addressable.
Adversarially reviewed by a fresh subagent: all six confirmed
behavior-neutral or behavior-improving, all touched packages pass -race,
golangci-lint confirms exactly 23 issues remain (not more, not fewer), and
none are new.
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package configuration
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
)
|
|
|
|
// ApplyOverlayValues decodes overrides (a nested map of dotted-path
|
|
// values, as produced by the overlay store) into cfg using the same
|
|
// field-level precedence as a file overlay: only the keys present are
|
|
// replaced, every field the overlay omits keeps its existing value.
|
|
//
|
|
// This is the decode half of the runtime config overlay. The loader's
|
|
// ApplyOverlay wraps it with defaulting, validation and provenance; the
|
|
// dashboard PATCH path calls it on a copy of the published config and
|
|
// validates the materialised result before persisting. Either way the
|
|
// caller owns the cfg value -- pass a copy when the base must survive.
|
|
func ApplyOverlayValues(cfg *config.Config, overrides map[string]any) error {
|
|
if len(overrides) == 0 {
|
|
return nil
|
|
}
|
|
data, err := yaml.Marshal(overrides)
|
|
if err != nil {
|
|
return fmt.Errorf("%w: encoding config overlay: %w", ErrUnreadable, err)
|
|
}
|
|
if err := yaml.Unmarshal(data, cfg); err != nil {
|
|
return fmt.Errorf("%w: parsing config overlay: %w", ErrUnreadable, err)
|
|
}
|
|
return nil
|
|
}
|