mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-20 00:03:53 +01:00
refactor(agent): extract agent pool and HTTP utilities to dedicated package
Moved non-agent-specific logic from agent/pkg/agent/ to internal/agentpool/: - pool.go: Agent pool management (Get, Add, Remove, List, Iter, etc.) - http_requests.go: HTTP utilities (health checks, forwarding, websockets, reverse proxy) - agent.go: Agent struct with HTTP client management This separates general-purpose pool management from agent-specific configuration, improving code organization and making the agent package focused on agent config only.
This commit is contained in:
@@ -15,7 +15,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||
"github.com/yusing/godoxy/internal/agentpool"
|
||||
config "github.com/yusing/godoxy/internal/config/types"
|
||||
"github.com/yusing/godoxy/internal/docker"
|
||||
"github.com/yusing/godoxy/internal/homepage"
|
||||
@@ -94,7 +94,7 @@ type (
|
||||
|
||||
provider types.RouteProvider
|
||||
|
||||
agent *agent.AgentConfig
|
||||
agent *agentpool.Agent
|
||||
|
||||
started chan struct{}
|
||||
onceStart sync.Once
|
||||
@@ -153,10 +153,10 @@ func (r *Route) validate() gperr.Error {
|
||||
}
|
||||
var ok bool
|
||||
// by agent address
|
||||
r.agent, ok = agent.GetAgent(r.Agent)
|
||||
r.agent, ok = agentpool.Get(r.Agent)
|
||||
if !ok {
|
||||
// fallback to get agent by name
|
||||
r.agent, ok = agent.GetAgentByName(r.Agent)
|
||||
r.agent, ok = agentpool.GetAgent(r.Agent)
|
||||
if !ok {
|
||||
return gperr.Errorf("agent %s not found", r.Agent)
|
||||
}
|
||||
@@ -510,7 +510,7 @@ func (r *Route) Type() route.RouteType {
|
||||
panic(fmt.Errorf("unexpected scheme %s for alias %s", r.Scheme, r.Alias))
|
||||
}
|
||||
|
||||
func (r *Route) GetAgent() *agent.AgentConfig {
|
||||
func (r *Route) GetAgent() *agentpool.Agent {
|
||||
if r.Container != nil && r.Container.Agent != nil {
|
||||
return r.Container.Agent
|
||||
}
|
||||
|
||||
@@ -6,8 +6,8 @@ import (
|
||||
|
||||
"github.com/pires/go-proxyproto"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||
"github.com/yusing/godoxy/internal/acl"
|
||||
"github.com/yusing/godoxy/internal/agentpool"
|
||||
"github.com/yusing/godoxy/internal/entrypoint"
|
||||
nettypes "github.com/yusing/godoxy/internal/net/types"
|
||||
ioutils "github.com/yusing/goutils/io"
|
||||
@@ -19,7 +19,7 @@ type TCPTCPStream struct {
|
||||
listener net.Listener
|
||||
laddr *net.TCPAddr
|
||||
dst *net.TCPAddr
|
||||
agent *agent.AgentConfig
|
||||
agent *agentpool.Agent
|
||||
|
||||
preDial nettypes.HookFunc
|
||||
onRead nettypes.HookFunc
|
||||
@@ -27,7 +27,7 @@ type TCPTCPStream struct {
|
||||
closed atomic.Bool
|
||||
}
|
||||
|
||||
func NewTCPTCPStream(network, listenAddr, dstAddr string, agentCfg *agent.AgentConfig) (nettypes.Stream, error) {
|
||||
func NewTCPTCPStream(network, listenAddr, dstAddr string, agent *agentpool.Agent) (nettypes.Stream, error) {
|
||||
dst, err := net.ResolveTCPAddr(network, dstAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -36,7 +36,7 @@ func NewTCPTCPStream(network, listenAddr, dstAddr string, agentCfg *agent.AgentC
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &TCPTCPStream{network: network, laddr: laddr, dst: dst, agent: agentCfg}, nil
|
||||
return &TCPTCPStream{network: network, laddr: laddr, dst: dst, agent: agent}, nil
|
||||
}
|
||||
|
||||
func (s *TCPTCPStream) ListenAndServe(ctx context.Context, preDial, onRead nettypes.HookFunc) {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/yusing/godoxy/agent/pkg/agent"
|
||||
"github.com/yusing/godoxy/internal/acl"
|
||||
"github.com/yusing/godoxy/internal/agentpool"
|
||||
nettypes "github.com/yusing/godoxy/internal/net/types"
|
||||
"github.com/yusing/goutils/synk"
|
||||
"go.uber.org/atomic"
|
||||
@@ -23,7 +23,7 @@ type UDPUDPStream struct {
|
||||
|
||||
laddr *net.UDPAddr
|
||||
dst *net.UDPAddr
|
||||
agent *agent.AgentConfig
|
||||
agent *agentpool.Agent
|
||||
|
||||
preDial nettypes.HookFunc
|
||||
onRead nettypes.HookFunc
|
||||
@@ -53,7 +53,7 @@ const (
|
||||
|
||||
var bufPool = synk.GetSizedBytesPool()
|
||||
|
||||
func NewUDPUDPStream(network, listenAddr, dstAddr string, agentCfg *agent.AgentConfig) (nettypes.Stream, error) {
|
||||
func NewUDPUDPStream(network, listenAddr, dstAddr string, agent *agentpool.Agent) (nettypes.Stream, error) {
|
||||
dst, err := net.ResolveUDPAddr(network, dstAddr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -66,7 +66,7 @@ func NewUDPUDPStream(network, listenAddr, dstAddr string, agentCfg *agent.AgentC
|
||||
network: network,
|
||||
laddr: laddr,
|
||||
dst: dst,
|
||||
agent: agentCfg,
|
||||
agent: agent,
|
||||
conns: make(map[string]*udpUDPConn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user