From c847fe4747e65a667a4ece1cdbacd008f91db827 Mon Sep 17 00:00:00 2001 From: yusing Date: Sun, 20 Oct 2024 11:04:44 +0800 Subject: [PATCH] fixed schema and json tag, hide http://:0 --- internal/proxy/entry/reverse_proxy.go | 6 +++--- internal/proxy/entry/stream.go | 6 +++--- internal/route/provider/file.go | 5 ++++- internal/watcher/health/json.go | 6 +++++- schema/providers.schema.json | 3 +-- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/internal/proxy/entry/reverse_proxy.go b/internal/proxy/entry/reverse_proxy.go index 7d62973..8d48652 100644 --- a/internal/proxy/entry/reverse_proxy.go +++ b/internal/proxy/entry/reverse_proxy.go @@ -16,9 +16,9 @@ import ( type ReverseProxyEntry struct { // real model after validation Raw *RawEntry `json:"raw"` - Alias fields.Alias `json:"alias,omitempty"` - Scheme fields.Scheme `json:"scheme,omitempty"` - URL net.URL `json:"url,omitempty"` + Alias fields.Alias `json:"alias"` + Scheme fields.Scheme `json:"scheme"` + URL net.URL `json:"url"` NoTLSVerify bool `json:"no_tls_verify,omitempty"` PathPatterns fields.PathPatterns `json:"path_patterns,omitempty"` HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty"` diff --git a/internal/proxy/entry/stream.go b/internal/proxy/entry/stream.go index 35ac4ef..4416b20 100644 --- a/internal/proxy/entry/stream.go +++ b/internal/proxy/entry/stream.go @@ -15,9 +15,9 @@ import ( type StreamEntry struct { Raw *RawEntry `json:"raw"` - Alias fields.Alias `json:"alias,omitempty"` - Scheme fields.StreamScheme `json:"scheme,omitempty"` - URL net.URL `json:"url,omitempty"` + Alias fields.Alias `json:"alias"` + Scheme fields.StreamScheme `json:"scheme"` + URL net.URL `json:"url"` Host fields.Host `json:"host,omitempty"` Port fields.StreamPort `json:"port,omitempty"` HealthCheck *health.HealthCheckConfig `json:"healthcheck,omitempty"` diff --git a/internal/route/provider/file.go b/internal/route/provider/file.go index 472ca9d..8f302e0 100644 --- a/internal/route/provider/file.go +++ b/internal/route/provider/file.go @@ -5,6 +5,7 @@ import ( "os" "path" + "github.com/sirupsen/logrus" "github.com/yusing/go-proxy/internal/common" E "github.com/yusing/go-proxy/internal/error" "github.com/yusing/go-proxy/internal/proxy/entry" @@ -61,7 +62,9 @@ func (p *FileProvider) LoadRoutesImpl() (routes R.Routes, res E.Error) { return } - b.Add(Validate(data), true) + if err := Validate(data); err != nil { + logrus.Warn(err) + } return R.FromEntries(entries) } diff --git a/internal/watcher/health/json.go b/internal/watcher/health/json.go index 6c27722..0c8ec23 100644 --- a/internal/watcher/health/json.go +++ b/internal/watcher/health/json.go @@ -19,6 +19,10 @@ type JSONRepresentation struct { } func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) { + url := jsonRepr.URL.String() + if url == "http://:0" { + url = "" + } return json.Marshal(map[string]any{ "name": jsonRepr.Name, "config": jsonRepr.Config, @@ -27,7 +31,7 @@ func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) { "status": jsonRepr.Status.String(), "uptime": jsonRepr.Uptime.Seconds(), "uptimeStr": U.FormatDuration(jsonRepr.Uptime), - "url": jsonRepr.URL, + "url": url, "extra": jsonRepr.Extra, }) } diff --git a/schema/providers.schema.json b/schema/providers.schema.json index fa458ee..519820a 100644 --- a/schema/providers.schema.json +++ b/schema/providers.schema.json @@ -122,8 +122,7 @@ "properties": { "link": { "type": "string", - "description": "Name and subdomain of load-balancer", - "format": "uri" + "description": "Name and subdomain of load-balancer" }, "mode": { "enum": [