api: fix validation and http response

This commit is contained in:
yusing
2025-01-04 09:01:52 +08:00
parent 112859caa5
commit c30d3f585f
6 changed files with 33 additions and 16 deletions

View File

@@ -31,8 +31,12 @@ func FileProviderImpl(filename string) (ProviderImpl, error) {
return impl, nil
}
func validate(data []byte) (route.RawEntries, E.Error) {
return utils.DeserializeYAMLMap[*route.RawEntry](data)
func validate(data []byte) (route.Routes, E.Error) {
entries, err := utils.DeserializeYAMLMap[*route.RawEntry](data)
if err != nil {
return route.NewRoutes(), err
}
return route.FromEntries(entries)
}
func Validate(data []byte) (err E.Error) {
@@ -56,11 +60,7 @@ func (p *FileProvider) loadRoutesImpl() (route.Routes, E.Error) {
return routes, E.From(err)
}
entries, err := validate(data)
if err == nil {
return route.FromEntries(entries)
}
return routes, E.From(err)
return validate(data)
}
func (p *FileProvider) NewWatcher() W.Watcher {