mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
fixed json output for ls-routes and its API and homepage api
This commit is contained in:
parent
f4d532598c
commit
56b778f19c
5 changed files with 23 additions and 12 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
"github.com/sirupsen/logrus"
|
||||
gphttp "github.com/yusing/go-proxy/internal/net/http"
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
||||
)
|
||||
|
||||
|
@ -72,6 +73,10 @@ func (w *Waker) Uptime() time.Duration {
|
|||
}
|
||||
|
||||
func (w *Waker) MarshalJSON() ([]byte, error) {
|
||||
var url types.URL
|
||||
if w.URL.String() != "http://:0" {
|
||||
url = w.URL
|
||||
}
|
||||
return (&health.JSONRepresentation{
|
||||
Name: w.Name(),
|
||||
Status: w.Status(),
|
||||
|
@ -79,7 +84,7 @@ func (w *Waker) MarshalJSON() ([]byte, error) {
|
|||
Interval: w.IdleTimeout,
|
||||
Timeout: w.WakeTimeout,
|
||||
},
|
||||
URL: w.URL,
|
||||
URL: url,
|
||||
}).MarshalJSON()
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,11 @@ func (u URL) String() string {
|
|||
return u.URL.String()
|
||||
}
|
||||
|
||||
func (u URL) MarshalText() (text []byte, err error) {
|
||||
return []byte(u.String()), nil
|
||||
func (u URL) MarshalJSON() (text []byte, err error) {
|
||||
if u.URL == nil {
|
||||
return []byte("null"), nil
|
||||
}
|
||||
return []byte("\"" + u.URL.String() + "\""), nil
|
||||
}
|
||||
|
||||
func (u URL) Equals(other *URL) bool {
|
||||
|
|
|
@ -54,7 +54,7 @@ func (rp *ReverseProxyEntry) UseIdleWatcher() bool {
|
|||
}
|
||||
|
||||
func (rp *ReverseProxyEntry) UseLoadBalance() bool {
|
||||
return rp.LoadBalance.Link != ""
|
||||
return rp.LoadBalance != nil && rp.LoadBalance.Link != ""
|
||||
}
|
||||
|
||||
func (rp *ReverseProxyEntry) IsDocker() bool {
|
||||
|
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
type (
|
||||
HTTPRoute struct {
|
||||
*P.ReverseProxyEntry `json:"entry"`
|
||||
*P.ReverseProxyEntry
|
||||
|
||||
HealthMon health.HealthMonitor `json:"health,omitempty"`
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/net/types"
|
||||
U "github.com/yusing/go-proxy/internal/utils"
|
||||
)
|
||||
|
||||
type JSONRepresentation struct {
|
||||
|
@ -22,9 +23,11 @@ func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
|
|||
"name": jsonRepr.Name,
|
||||
"config": jsonRepr.Config,
|
||||
"started": jsonRepr.Started.Unix(),
|
||||
"startedStr": U.FormatTime(jsonRepr.Started),
|
||||
"status": jsonRepr.Status.String(),
|
||||
"uptime": jsonRepr.Uptime.Seconds(),
|
||||
"url": jsonRepr.URL.String(),
|
||||
"uptimeStr": U.FormatDuration(jsonRepr.Uptime),
|
||||
"url": jsonRepr.URL,
|
||||
"extra": jsonRepr.Extra,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue