fixed schema and json tag, hide http://:0

This commit is contained in:
yusing 2024-10-20 11:04:44 +08:00
parent a278711421
commit c847fe4747
5 changed files with 16 additions and 10 deletions

View file

@ -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"`

View file

@ -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"`

View file

@ -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)
}

View file

@ -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,
})
}

View file

@ -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": [