fixed json output for ls-routes and its API and homepage api

This commit is contained in:
yusing
2024-10-15 16:23:46 +08:00
parent f4d532598c
commit 56b778f19c
5 changed files with 23 additions and 12 deletions

View File

@@ -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 {
@@ -19,12 +20,14 @@ type JSONRepresentation struct {
func (jsonRepr *JSONRepresentation) MarshalJSON() ([]byte, error) {
return json.Marshal(map[string]any{
"name": jsonRepr.Name,
"config": jsonRepr.Config,
"started": jsonRepr.Started.Unix(),
"status": jsonRepr.Status.String(),
"uptime": jsonRepr.Uptime.Seconds(),
"url": jsonRepr.URL.String(),
"extra": jsonRepr.Extra,
"name": jsonRepr.Name,
"config": jsonRepr.Config,
"started": jsonRepr.Started.Unix(),
"startedStr": U.FormatTime(jsonRepr.Started),
"status": jsonRepr.Status.String(),
"uptime": jsonRepr.Uptime.Seconds(),
"uptimeStr": U.FormatDuration(jsonRepr.Uptime),
"url": jsonRepr.URL,
"extra": jsonRepr.Extra,
})
}