mirror of
https://github.com/yusing/godoxy.git
synced 2025-06-09 04:52:35 +02:00
uses display name in uptime metrics, small refactor
This commit is contained in:
parent
0da183f084
commit
1af6dd9cf8
4 changed files with 35 additions and 25 deletions
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/lithammer/fuzzysearch/fuzzy"
|
||||
"github.com/yusing/go-proxy/internal/metrics/period"
|
||||
metricsutils "github.com/yusing/go-proxy/internal/metrics/utils"
|
||||
"github.com/yusing/go-proxy/internal/route/routes"
|
||||
"github.com/yusing/go-proxy/internal/route/routes/routequery"
|
||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
||||
)
|
||||
|
@ -119,6 +120,10 @@ func (rs RouteStatuses) aggregate(limit int, offset int) Aggregated {
|
|||
"avg_latency": latency,
|
||||
"statuses": statuses,
|
||||
}
|
||||
r, ok := routes.GetRoute(alias)
|
||||
if ok {
|
||||
result[i]["display_name"] = r.HomepageConfig().Name
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -5,11 +5,13 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/yusing/go-proxy/agent/pkg/agent"
|
||||
"github.com/yusing/go-proxy/internal"
|
||||
"github.com/yusing/go-proxy/internal/docker"
|
||||
idlewatcher "github.com/yusing/go-proxy/internal/docker/idlewatcher/types"
|
||||
"github.com/yusing/go-proxy/internal/homepage"
|
||||
net "github.com/yusing/go-proxy/internal/net/types"
|
||||
"github.com/yusing/go-proxy/internal/task"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
||||
|
||||
dockertypes "github.com/docker/docker/api/types"
|
||||
|
@ -358,6 +360,26 @@ func (r *Route) Finalize() {
|
|||
if r.Homepage.IsEmpty() {
|
||||
r.Homepage = homepage.NewItem(r.Alias)
|
||||
}
|
||||
|
||||
if r.Homepage.Name == "" {
|
||||
var key string
|
||||
if r.Container != nil {
|
||||
key = r.Container.ImageName
|
||||
} else {
|
||||
key = r.Alias
|
||||
}
|
||||
displayName, ok := internal.GetDisplayName(key)
|
||||
if ok {
|
||||
r.Homepage.Name = displayName
|
||||
} else {
|
||||
r.Homepage.Name = strutils.Title(
|
||||
strings.ReplaceAll(
|
||||
strings.ReplaceAll(r.Alias, "-", " "),
|
||||
"_", " ",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func lowestPort(ports map[int]dockertypes.Port) (res int) {
|
||||
|
|
|
@ -4,12 +4,10 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/yusing/go-proxy/internal"
|
||||
"github.com/yusing/go-proxy/internal/homepage"
|
||||
provider "github.com/yusing/go-proxy/internal/route/provider/types"
|
||||
"github.com/yusing/go-proxy/internal/route/routes"
|
||||
route "github.com/yusing/go-proxy/internal/route/types"
|
||||
"github.com/yusing/go-proxy/internal/utils/strutils"
|
||||
"github.com/yusing/go-proxy/internal/watcher/health"
|
||||
)
|
||||
|
||||
|
@ -87,10 +85,6 @@ func HomepageConfig(useDefaultCategories bool, categoryFilter, providerFilter st
|
|||
routes.GetHTTPRoutes().RangeAll(func(alias string, r route.HTTPRoute) {
|
||||
item := r.HomepageConfig()
|
||||
|
||||
if item.IsEmpty() {
|
||||
item = homepage.NewItem(alias)
|
||||
}
|
||||
|
||||
if override := item.GetOverride(); override != item {
|
||||
if providerFilter != "" && override.Provider != providerFilter ||
|
||||
categoryFilter != "" && override.Category != categoryFilter {
|
||||
|
@ -107,25 +101,6 @@ func HomepageConfig(useDefaultCategories bool, categoryFilter, providerFilter st
|
|||
return
|
||||
}
|
||||
|
||||
if item.Name == "" {
|
||||
reference := r.TargetName()
|
||||
cont := r.ContainerInfo()
|
||||
if cont != nil {
|
||||
reference = cont.ImageName
|
||||
}
|
||||
name, ok := internal.GetDisplayName(reference)
|
||||
if ok {
|
||||
item.Name = name
|
||||
} else {
|
||||
item.Name = strutils.Title(
|
||||
strings.ReplaceAll(
|
||||
strings.ReplaceAll(alias, "-", " "),
|
||||
"_", " ",
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if useDefaultCategories {
|
||||
container := r.ContainerInfo()
|
||||
if container != nil && item.Category == "" {
|
||||
|
|
|
@ -48,6 +48,14 @@ func GetStreamRoute(alias string) (types.StreamRoute, bool) {
|
|||
return streamRoutes.Load(alias)
|
||||
}
|
||||
|
||||
func GetRoute(alias string) (types.Route, bool) {
|
||||
r, ok := httpRoutes.Load(alias)
|
||||
if ok {
|
||||
return r, true
|
||||
}
|
||||
return streamRoutes.Load(alias)
|
||||
}
|
||||
|
||||
func SetHTTPRoute(alias string, r types.HTTPRoute) {
|
||||
httpRoutes.Store(alias, r)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue