This commit is contained in:
yusing
2026-02-16 08:59:01 +08:00
parent 15b9635ee1
commit e4e6f6b3e8
242 changed files with 3953 additions and 3502 deletions

View File

@@ -59,7 +59,7 @@ func (cfg *DockerProviderConfig) Parse(value string) error {
return nil
}
func (cfg *DockerProviderConfig) UnmarshalMap(m map[string]any) gperr.Error {
func (cfg *DockerProviderConfig) UnmarshalMap(m map[string]any) error {
var tmp DockerProviderConfigDetailed
var err = serialization.MapUnmarshalValidate(m, &tmp)
if err != nil {
@@ -70,7 +70,7 @@ func (cfg *DockerProviderConfig) UnmarshalMap(m map[string]any) gperr.Error {
cfg.TLS = tmp.TLS
if cfg.TLS != nil {
if err := checkFilesOk(cfg.TLS.CAFile, cfg.TLS.CertFile, cfg.TLS.KeyFile); err != nil {
return gperr.Wrap(err)
return err
}
}
return nil

View File

@@ -73,6 +73,17 @@ type (
Config *LoadBalancerConfig `json:"config"`
Pool map[string]any `json:"pool"`
} // @name HealthExtra
HealthInfoWithoutDetail struct {
Status HealthStatus `json:"status" swaggertype:"string" enums:"healthy,unhealthy,napping,starting,error,unknown"`
Uptime time.Duration `json:"uptime" swaggertype:"number"`
Latency time.Duration `json:"latency" swaggertype:"number"`
} // @name HealthInfoWithoutDetail
HealthInfo struct {
HealthInfoWithoutDetail
Detail string `json:"detail"`
} // @name HealthInfo
)
const (

View File

@@ -1,6 +1,7 @@
package types
import (
"errors"
"net/url"
"strconv"
"strings"
@@ -32,7 +33,7 @@ type (
DependsOn []string `json:"depends_on,omitempty"`
NoLoadingPage bool `json:"no_loading_page,omitempty"`
valErr gperr.Error
valErr error
} // @name IdlewatcherConfig
ContainerStopMethod string // @name ContainerStopMethod
ContainerSignal string // @name ContainerSignal
@@ -44,7 +45,7 @@ type (
} // @name IdlewatcherDockerConfig
ProxmoxConfig struct {
Node string `json:"node" validate:"required"`
VMID int `json:"vmid" validate:"required"`
VMID uint64 `json:"vmid" validate:"required"`
} // @name IdlewatcherProxmoxNodeConfig
)
@@ -57,21 +58,28 @@ const (
ContainerStopMethodKill ContainerStopMethod = "kill"
)
var (
ErrMissingProviderConfig = errors.New("missing idlewatcher provider config")
ErrInvalidStopMethod = errors.New("invalid stop method")
ErrInvalidStopSignal = errors.New("invalid stop signal")
ErrEmptyStartEndpoint = errors.New("start endpoint must not be empty if defined")
)
func (c *IdlewatcherConfig) Key() string {
if c.Docker != nil {
return c.Docker.ContainerID
}
return c.Proxmox.Node + ":" + strconv.Itoa(c.Proxmox.VMID)
return c.Proxmox.Node + ":" + strconv.FormatUint(c.Proxmox.VMID, 10)
}
func (c *IdlewatcherConfig) ContainerName() string {
if c.Docker != nil {
return c.Docker.ContainerName
}
return "lxc-" + strconv.Itoa(c.Proxmox.VMID)
return "lxc-" + strconv.FormatUint(c.Proxmox.VMID, 10)
}
func (c *IdlewatcherConfig) Validate() gperr.Error {
func (c *IdlewatcherConfig) Validate() error {
if c.IdleTimeout == 0 { // zero idle timeout means no idle watcher
c.valErr = nil
return nil
@@ -89,13 +97,13 @@ func (c *IdlewatcherConfig) Validate() gperr.Error {
return c.valErr
}
func (c *IdlewatcherConfig) ValErr() gperr.Error {
func (c *IdlewatcherConfig) ValErr() error {
return c.valErr
}
func (c *IdlewatcherConfig) validateProvider() error {
if c.Docker == nil && c.Proxmox == nil {
return gperr.New("missing idlewatcher provider config")
return ErrMissingProviderConfig
}
return nil
}
@@ -118,16 +126,16 @@ func (c *IdlewatcherConfig) validateStopMethod() error {
case ContainerStopMethodPause, ContainerStopMethodStop, ContainerStopMethodKill:
return nil
default:
return gperr.New("invalid stop method").Subject(string(c.StopMethod))
return gperr.PrependSubject(ErrInvalidStopMethod, string(c.StopMethod))
}
}
func (c *IdlewatcherConfig) validateStopSignal() error {
switch c.StopSignal {
case "", "SIGINT", "SIGTERM", "SIGQUIT", "SIGHUP", "INT", "TERM", "QUIT", "HUP":
case "", "SIGINT", "SIGTERM", "SIGKILL", "SIGQUIT", "SIGHUP", "INT", "TERM", "KILL", "QUIT", "HUP":
return nil
default:
return gperr.New("invalid stop signal").Subject(string(c.StopSignal))
return gperr.PrependSubject(ErrInvalidStopSignal, string(c.StopSignal))
}
}
@@ -141,7 +149,7 @@ func (c *IdlewatcherConfig) validateStartEndpoint() error {
c.StartEndpoint = c.StartEndpoint[:i]
}
if len(c.StartEndpoint) == 0 {
return gperr.New("start endpoint must not be empty if defined")
return ErrEmptyStartEndpoint
}
_, err := url.ParseRequestURI(c.StartEndpoint)
return err

View File

@@ -3,11 +3,11 @@ package types
import (
"net/http"
"github.com/rs/zerolog"
"github.com/yusing/godoxy/internal/agentpool"
"github.com/yusing/godoxy/internal/homepage"
nettypes "github.com/yusing/godoxy/internal/net/types"
provider "github.com/yusing/godoxy/internal/route/provider/types"
gperr "github.com/yusing/goutils/errs"
"github.com/yusing/goutils/http/reverseproxy"
"github.com/yusing/goutils/pool"
"github.com/yusing/goutils/task"
@@ -18,8 +18,11 @@ type (
task.TaskStarter
task.TaskFinisher
pool.Object
zerolog.LogObjectMarshaler
ProviderName() string
GetProvider() RouteProvider
ListenURL() *nettypes.URL
TargetURL() *nettypes.URL
HealthMonitor() HealthMonitor
SetHealthMonitor(m HealthMonitor)
@@ -62,8 +65,8 @@ type (
Stream() nettypes.Stream
}
RouteProvider interface {
Start(task.Parent) gperr.Error
LoadRoutes() gperr.Error
Start(parent task.Parent) error
LoadRoutes() error
GetRoute(alias string) (r Route, ok bool)
// should be used like `for _, r := range p.IterRoutes` (no braces), not calling it directly
IterRoutes(yield func(alias string, r Route) bool)