fix(config): discover mounted yml config

This commit is contained in:
tiennm99 committed 2026-06-28 14:05:48 +07:00
1 parent 9a69030179
commit 08da9dcb84
4 files changed
+68 -4

No files matched your search

+23
View File
@@ -1,6 +1,7 @@
package main
import (
"errors"
"fmt"
"net"
"net/url"
@@ -18,6 +19,13 @@ const (
defaultCounterKey = "counter"
)
var defaultConfigFiles = []string{
"keepalive.yaml",
"keepalive.yml",
"/keepalive.yaml",
"/keepalive.yml",
}
type appConfig struct {
Interval string `json:"interval" yaml:"interval"`
CounterKey string `json:"counter_key" yaml:"counter_key"`
@@ -52,6 +60,21 @@ func loadConfigFile(path string) ([]serviceConfig, error) {
return normalizeConfig(raw)
}
func defaultConfigFile() (string, error) {
return firstExistingConfigFile(defaultConfigFiles)
}
func firstExistingConfigFile(paths []string) (string, error) {
for _, path := range paths {
if _, err := os.Stat(path); err == nil {
return path, nil
} else if !errors.Is(err, os.ErrNotExist) {
return "", err
}
}
return "", fmt.Errorf("config file not found (looked for: %s)", strings.Join(paths, ", "))
}
func normalizeConfig(raw appConfig) ([]serviceConfig, error) {
if len(raw.Services) == 0 {
return nil, fmt.Errorf("services must contain at least one service")