From d1c9d4e4ad8070ed86885ca058a61eab5cbb0eb2 Mon Sep 17 00:00:00 2001 From: Snider Date: Wed, 18 Mar 2026 01:00:47 +0000 Subject: [PATCH] refactor: generic EtcGet[T] replaces typed getter boilerplate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetString/GetInt/GetBool now delegate to EtcGet[T]. Gemini Pro review finding — three identical functions collapsed to one generic. Co-Authored-By: Virgil --- pkg/core/etc.go | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/pkg/core/etc.go b/pkg/core/etc.go index 136caa5..3a58016 100644 --- a/pkg/core/etc.go +++ b/pkg/core/etc.go @@ -69,33 +69,24 @@ func (e *Etc) Get(key string) (any, bool) { } // GetString retrieves a string configuration value. -func (e *Etc) GetString(key string) string { - val, ok := e.Get(key) - if !ok { - return "" - } - s, _ := val.(string) - return s -} +func (e *Etc) GetString(key string) string { return EtcGet[string](e, key) } // GetInt retrieves an int configuration value. -func (e *Etc) GetInt(key string) int { - val, ok := e.Get(key) - if !ok { - return 0 - } - i, _ := val.(int) - return i -} +func (e *Etc) GetInt(key string) int { return EtcGet[int](e, key) } // GetBool retrieves a bool configuration value. -func (e *Etc) GetBool(key string) bool { +func (e *Etc) GetBool(key string) bool { return EtcGet[bool](e, key) } + +// EtcGet retrieves a typed configuration value. +// Returns zero value if key is missing or type doesn't match. +func EtcGet[T any](e *Etc, key string) T { val, ok := e.Get(key) if !ok { - return false + var zero T + return zero } - b, _ := val.(bool) - return b + typed, _ := val.(T) + return typed } // --- Feature Flags ---