mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-31 14:13:09 +02:00
replace all schema check with go-playground/validator/v10
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/yusing/go-proxy/internal/common"
|
||||
E "github.com/yusing/go-proxy/internal/error"
|
||||
"github.com/yusing/go-proxy/internal/route"
|
||||
U "github.com/yusing/go-proxy/internal/utils"
|
||||
"github.com/yusing/go-proxy/internal/utils"
|
||||
W "github.com/yusing/go-proxy/internal/watcher"
|
||||
)
|
||||
|
||||
@@ -31,8 +31,9 @@ func FileProviderImpl(filename string) (ProviderImpl, error) {
|
||||
return impl, nil
|
||||
}
|
||||
|
||||
func Validate(data []byte) E.Error {
|
||||
return U.ValidateYaml(U.GetSchema(common.FileProviderSchemaPath), data)
|
||||
func Validate(data []byte) (err E.Error) {
|
||||
_, err = utils.DeserializeYAMLMap[*route.RawEntry](data)
|
||||
return
|
||||
}
|
||||
|
||||
func (p *FileProvider) String() string {
|
||||
@@ -45,22 +46,17 @@ func (p *FileProvider) Logger() *zerolog.Logger {
|
||||
|
||||
func (p *FileProvider) loadRoutesImpl() (route.Routes, E.Error) {
|
||||
routes := route.NewRoutes()
|
||||
entries := route.NewProxyEntries()
|
||||
|
||||
data, err := os.ReadFile(p.path)
|
||||
if err != nil {
|
||||
return routes, E.From(err)
|
||||
}
|
||||
|
||||
if err := entries.UnmarshalFromYAML(data); err != nil {
|
||||
return routes, E.From(err)
|
||||
entries, err := utils.DeserializeYAMLMap[*route.RawEntry](data)
|
||||
if err == nil {
|
||||
return route.FromEntries(entries)
|
||||
}
|
||||
|
||||
if err := Validate(data); err != nil {
|
||||
E.LogWarn("validation failure", err.Subject(p.fileName))
|
||||
}
|
||||
|
||||
return route.FromEntries(entries)
|
||||
return routes, E.From(err)
|
||||
}
|
||||
|
||||
func (p *FileProvider) NewWatcher() W.Watcher {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/yusing/go-proxy/internal/watcher/health/monitor"
|
||||
)
|
||||
|
||||
// TODO: support stream load balance
|
||||
// TODO: support stream load balance.
|
||||
type StreamRoute struct {
|
||||
*entry.StreamEntry
|
||||
|
||||
|
||||
@@ -24,20 +24,20 @@ type (
|
||||
|
||||
// raw entry object before validation
|
||||
// loaded from docker labels or yaml file
|
||||
Alias string `json:"-" yaml:"-"`
|
||||
Scheme string `json:"scheme,omitempty" yaml:"scheme"`
|
||||
Host string `json:"host,omitempty" yaml:"host"`
|
||||
Port string `json:"port,omitempty" yaml:"port"`
|
||||
NoTLSVerify bool `json:"no_tls_verify,omitempty" yaml:"no_tls_verify"` // https proxy only
|
||||
PathPatterns []string `json:"path_patterns,omitempty" yaml:"path_patterns"` // http(s) proxy only
|
||||
HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty" yaml:"healthcheck"`
|
||||
LoadBalance *loadbalance.Config `json:"load_balance,omitempty" yaml:"load_balance"`
|
||||
Middlewares map[string]docker.LabelMap `json:"middlewares,omitempty" yaml:"middlewares"`
|
||||
Homepage *homepage.Item `json:"homepage,omitempty" yaml:"homepage"`
|
||||
AccessLog *accesslog.Config `json:"access_log,omitempty" yaml:"access_log"`
|
||||
Alias string `json:"-"`
|
||||
Scheme string `json:"scheme,omitempty"`
|
||||
Host string `json:"host,omitempty"`
|
||||
Port string `json:"port,omitempty"`
|
||||
NoTLSVerify bool `json:"no_tls_verify,omitempty"`
|
||||
PathPatterns []string `json:"path_patterns,omitempty"`
|
||||
HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty"`
|
||||
LoadBalance *loadbalance.Config `json:"load_balance,omitempty"`
|
||||
Middlewares map[string]docker.LabelMap `json:"middlewares,omitempty"`
|
||||
Homepage *homepage.Item `json:"homepage,omitempty"`
|
||||
AccessLog *accesslog.Config `json:"access_log,omitempty"`
|
||||
|
||||
/* Docker only */
|
||||
Container *docker.Container `json:"container,omitempty" yaml:"-"`
|
||||
Container *docker.Container `json:"container,omitempty"`
|
||||
|
||||
finalized bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user