refactor(config): enhance provider conflict error messages, streamline provider loading, and improve validation for config files, rename provider.GetType() to Type()

This commit is contained in:
yusing
2025-04-05 13:30:24 +08:00
parent 73a5c57d67
commit b53dd17b84
4 changed files with 35 additions and 47 deletions

View File

@@ -73,7 +73,7 @@ func (handler *EventHandler) matchAny(events []watcher.Event, route *route.Route
}
func (handler *EventHandler) match(event watcher.Event, route *route.Route) bool {
switch handler.provider.GetType() {
switch handler.provider.Type() {
case types.ProviderTypeDocker, types.ProviderTypeAgent:
return route.Container.ContainerID == event.ActorID ||
route.Container.ContainerName == event.ActorName

View File

@@ -20,17 +20,12 @@ type FileProvider struct {
l zerolog.Logger
}
func FileProviderImpl(filename string) (ProviderImpl, error) {
impl := &FileProvider{
func FileProviderImpl(filename string) ProviderImpl {
return &FileProvider{
fileName: filename,
path: path.Join(common.ConfigBasePath, filename),
l: logging.With().Str("type", "file").Str("name", filename).Logger(),
}
_, err := os.Stat(impl.path)
if err != nil {
return nil, err
}
return impl, nil
}
func validate(data []byte) (routes route.Routes, err gperr.Error) {