mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
initial support of homepage labels
This commit is contained in:
parent
ae61a2335d
commit
90130411f9
7 changed files with 76 additions and 39 deletions
|
@ -17,6 +17,7 @@ const (
|
||||||
ListMiddlewares = "middlewares"
|
ListMiddlewares = "middlewares"
|
||||||
ListMiddlewareTrace = "middleware_trace"
|
ListMiddlewareTrace = "middleware_trace"
|
||||||
ListMatchDomains = "match_domains"
|
ListMatchDomains = "match_domains"
|
||||||
|
ListHomepageConfig = "homepage_config"
|
||||||
)
|
)
|
||||||
|
|
||||||
func List(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
func List(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -36,6 +37,8 @@ func List(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
||||||
listMiddlewareTrace(w, r)
|
listMiddlewareTrace(w, r)
|
||||||
case ListMatchDomains:
|
case ListMatchDomains:
|
||||||
listMatchDomains(cfg, w, r)
|
listMatchDomains(cfg, w, r)
|
||||||
|
case ListHomepageConfig:
|
||||||
|
listHomepageConfig(cfg, w, r)
|
||||||
default:
|
default:
|
||||||
U.HandleErr(w, r, U.ErrInvalidKey("what"), http.StatusBadRequest)
|
U.HandleErr(w, r, U.ErrInvalidKey("what"), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
|
@ -78,3 +81,7 @@ func listMiddlewares(w http.ResponseWriter, r *http.Request) {
|
||||||
func listMatchDomains(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
func listMatchDomains(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
||||||
U.HandleErr(w, r, U.RespondJson(w, cfg.Value().MatchDomains))
|
U.HandleErr(w, r, U.RespondJson(w, cfg.Value().MatchDomains))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listHomepageConfig(cfg *config.Config, w http.ResponseWriter, r *http.Request) {
|
||||||
|
U.HandleErr(w, r, U.RespondJson(w, cfg.HomepageConfig()))
|
||||||
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
H "github.com/yusing/go-proxy/internal/homepage"
|
||||||
M "github.com/yusing/go-proxy/internal/models"
|
M "github.com/yusing/go-proxy/internal/models"
|
||||||
PR "github.com/yusing/go-proxy/internal/proxy/provider"
|
PR "github.com/yusing/go-proxy/internal/proxy/provider"
|
||||||
R "github.com/yusing/go-proxy/internal/route"
|
R "github.com/yusing/go-proxy/internal/route"
|
||||||
|
@ -24,6 +25,17 @@ func (cfg *Config) DumpProviders() map[string]*PR.Provider {
|
||||||
return entries
|
return entries
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (cfg *Config) HomepageConfig() H.HomePageConfig {
|
||||||
|
hpCfg := H.NewHomePageConfig()
|
||||||
|
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) {
|
||||||
|
if !r.Started() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
hpCfg.Add(*r.Entry().Homepage)
|
||||||
|
})
|
||||||
|
return hpCfg
|
||||||
|
}
|
||||||
|
|
||||||
func (cfg *Config) RoutesByAlias() map[string]U.SerializedObject {
|
func (cfg *Config) RoutesByAlias() map[string]U.SerializedObject {
|
||||||
routes := make(map[string]U.SerializedObject)
|
routes := make(map[string]U.SerializedObject)
|
||||||
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) {
|
cfg.forEachRoute(func(alias string, r R.Route, p *PR.Provider) {
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
package docker
|
|
||||||
|
|
||||||
type (
|
|
||||||
HomePageConfig struct{ m map[string]HomePageCategory }
|
|
||||||
HomePageCategory []HomePageItem
|
|
||||||
|
|
||||||
HomePageItem struct {
|
|
||||||
Name string
|
|
||||||
Icon string
|
|
||||||
Category string
|
|
||||||
Description string
|
|
||||||
WidgetConfig map[string]any
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func NewHomePageConfig() *HomePageConfig {
|
|
||||||
return &HomePageConfig{m: make(map[string]HomePageCategory)}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewHomePageItem() *HomePageItem {
|
|
||||||
return &HomePageItem{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HomePageConfig) Clear() {
|
|
||||||
c.m = make(map[string]HomePageCategory)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *HomePageConfig) Add(item HomePageItem) {
|
|
||||||
c.m[item.Category] = HomePageCategory{item}
|
|
||||||
}
|
|
||||||
|
|
||||||
const NSHomePage = "homepage"
|
|
|
@ -3,7 +3,8 @@ package docker
|
||||||
const (
|
const (
|
||||||
WildcardAlias = "*"
|
WildcardAlias = "*"
|
||||||
|
|
||||||
NSProxy = "proxy"
|
NSProxy = "proxy"
|
||||||
|
NSHomePage = "homepage"
|
||||||
|
|
||||||
LabelAliases = NSProxy + ".aliases"
|
LabelAliases = NSProxy + ".aliases"
|
||||||
LabelExclude = NSProxy + ".exclude"
|
LabelExclude = NSProxy + ".exclude"
|
||||||
|
|
37
internal/homepage/homepage.go
Normal file
37
internal/homepage/homepage.go
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
package homepage
|
||||||
|
|
||||||
|
type (
|
||||||
|
HomePageConfig map[string]HomePageCategory
|
||||||
|
HomePageCategory []HomePageItem
|
||||||
|
|
||||||
|
HomePageItem struct {
|
||||||
|
Name string `yaml:"name" json:"name"`
|
||||||
|
Icon string `yaml:"icon" json:"icon,omitempty"` // URL or unicodes
|
||||||
|
Category string `yaml:"category" json:"category"`
|
||||||
|
Description string `yaml:"description" json:"description,omitempty"`
|
||||||
|
WidgetConfig map[string]any `yaml:",flow" json:"widget_config,omitempty"`
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewHomePageConfig() HomePageConfig {
|
||||||
|
return HomePageConfig(make(map[string]HomePageCategory))
|
||||||
|
}
|
||||||
|
|
||||||
|
func HomePageItemDefault() *HomePageItem {
|
||||||
|
return &HomePageItem{
|
||||||
|
Name: "Docker",
|
||||||
|
Category: "Uncategorized",
|
||||||
|
WidgetConfig: make(map[string]any),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *HomePageConfig) Clear() {
|
||||||
|
*c = make(HomePageConfig)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c HomePageConfig) Add(item HomePageItem) {
|
||||||
|
if c[item.Category] == nil {
|
||||||
|
c[item.Category] = make(HomePageCategory, 0)
|
||||||
|
}
|
||||||
|
c[item.Category] = append(c[item.Category], item)
|
||||||
|
}
|
|
@ -7,6 +7,8 @@ import (
|
||||||
|
|
||||||
. "github.com/yusing/go-proxy/internal/common"
|
. "github.com/yusing/go-proxy/internal/common"
|
||||||
D "github.com/yusing/go-proxy/internal/docker"
|
D "github.com/yusing/go-proxy/internal/docker"
|
||||||
|
H "github.com/yusing/go-proxy/internal/homepage"
|
||||||
|
U "github.com/yusing/go-proxy/internal/utils"
|
||||||
F "github.com/yusing/go-proxy/internal/utils/functional"
|
F "github.com/yusing/go-proxy/internal/utils/functional"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,9 +20,10 @@ type (
|
||||||
Scheme string `yaml:"scheme" json:"scheme"`
|
Scheme string `yaml:"scheme" json:"scheme"`
|
||||||
Host string `yaml:"host" json:"host"`
|
Host string `yaml:"host" json:"host"`
|
||||||
Port string `yaml:"port" json:"port"`
|
Port string `yaml:"port" json:"port"`
|
||||||
NoTLSVerify bool `yaml:"no_tls_verify" json:"no_tls_verify"` // https proxy only
|
NoTLSVerify bool `yaml:"no_tls_verify" json:"no_tls_verify,omitempty"` // https proxy only
|
||||||
PathPatterns []string `yaml:"path_patterns" json:"path_patterns"` // http(s) proxy only
|
PathPatterns []string `yaml:"path_patterns" json:"path_patterns,omitempty"` // http(s) proxy only
|
||||||
Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares"`
|
Middlewares D.NestedLabelMap `yaml:"middlewares" json:"middlewares,omitempty"`
|
||||||
|
Homepage *H.HomePageItem `yaml:"homepage" json:"homepage"`
|
||||||
|
|
||||||
/* Docker only */
|
/* Docker only */
|
||||||
*D.ProxyProperties `yaml:"-" json:"proxy_properties"`
|
*D.ProxyProperties `yaml:"-" json:"proxy_properties"`
|
||||||
|
@ -37,6 +40,11 @@ func (e *RawEntry) FillMissingFields() {
|
||||||
e.ProxyProperties = &D.ProxyProperties{}
|
e.ProxyProperties = &D.ProxyProperties{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if e.Homepage == nil {
|
||||||
|
e.Homepage = H.HomePageItemDefault()
|
||||||
|
e.Homepage.Name = U.Title(e.Alias)
|
||||||
|
}
|
||||||
|
|
||||||
lp, pp, extra := e.splitPorts()
|
lp, pp, extra := e.splitPorts()
|
||||||
|
|
||||||
if port, ok := ServiceNamePortMapTCP[e.ImageName]; ok {
|
if port, ok := ServiceNamePortMapTCP[e.ImageName]; ok {
|
||||||
|
|
|
@ -5,9 +5,13 @@ import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
E "github.com/yusing/go-proxy/internal/error"
|
"golang.org/x/text/cases"
|
||||||
|
"golang.org/x/text/language"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// TODO: support other languages
|
||||||
|
var titleCaser = cases.Title(language.AmericanEnglish)
|
||||||
|
|
||||||
func CommaSeperatedList(s string) []string {
|
func CommaSeperatedList(s string) []string {
|
||||||
res := strings.Split(s, ",")
|
res := strings.Split(s, ",")
|
||||||
for i, part := range res {
|
for i, part := range res {
|
||||||
|
@ -16,8 +20,8 @@ func CommaSeperatedList(s string) []string {
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
func IntParser(value string) (int, E.NestedError) {
|
func Title(s string) string {
|
||||||
return E.Check(strconv.Atoi(value))
|
return titleCaser.String(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractPort(fullURL string) (int, error) {
|
func ExtractPort(fullURL string) (int, error) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue