Cleanup and refactor.

This commit is contained in:
2025-12-14 18:17:20 +00:00
parent 5d600043f0
commit 6cb4f91ece
17 changed files with 70 additions and 180 deletions
-5
View File
@@ -22,11 +22,6 @@ type ValidationError struct {
Context map[string]string // Additional context information
}
// Error implements the error interface.
func (e ValidationError) Error() string {
return e.Message
}
// Validator validates configuration files.
type Validator struct{}
-9
View File
@@ -621,15 +621,6 @@ func TestFormatValidationErrors(t *testing.T) {
}
}
func TestValidationError_Error(t *testing.T) {
err := ValidationError{
Field: "port",
Message: "Invalid port 0",
}
assert.Equal(t, "Invalid port 0", err.Error(), "Error() should return the message")
}
func TestValidator_ValidateStructure(t *testing.T) {
validator := NewValidator()
+6 -2
View File
@@ -22,6 +22,7 @@ type Watcher struct {
done chan struct{}
verbose bool
wg sync.WaitGroup // Ensures watch goroutine exits before Stop returns
stopOnce sync.Once // Ensures Stop is safe to call multiple times
}
// NewWatcher creates a new file watcher for the given config file.
@@ -61,9 +62,12 @@ func (w *Watcher) Start() {
}
// Stop stops watching the configuration file and waits for the watch goroutine to exit.
// Safe to call multiple times.
func (w *Watcher) Stop() {
close(w.done)
_ = w.watcher.Close()
w.stopOnce.Do(func() {
close(w.done)
_ = w.watcher.Close()
})
w.wg.Wait() // Wait for watch goroutine to exit
}