mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-21 04:52:35 +02:00
38 lines
966 B
Go
38 lines
966 B
Go
package config
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/yusing/go-proxy/agent/pkg/agent"
|
|
"github.com/yusing/go-proxy/internal/utils/functional"
|
|
)
|
|
|
|
var agentPool = functional.NewMapOf[string, *agent.AgentConfig]()
|
|
|
|
func addAgent(agent *agent.AgentConfig) {
|
|
agentPool.Store(agent.Addr, agent)
|
|
}
|
|
|
|
func removeAllAgents() {
|
|
agentPool.Clear()
|
|
}
|
|
|
|
func GetAgent(addr string) (agent *agent.AgentConfig, ok bool) {
|
|
agent, ok = agentPool.Load(addr)
|
|
return
|
|
}
|
|
|
|
func (cfg *Config) GetAgent(agentDockerHost string) (*agent.AgentConfig, bool) {
|
|
if !agent.IsDockerHostAgent(agentDockerHost) {
|
|
panic(errors.New("invalid use of GetAgent with docker host: " + agentDockerHost))
|
|
}
|
|
return GetAgent(agent.GetAgentAddrFromDockerHost(agentDockerHost))
|
|
}
|
|
|
|
func (cfg *Config) ListAgents() []*agent.AgentConfig {
|
|
agents := make([]*agent.AgentConfig, 0, agentPool.Size())
|
|
agentPool.RangeAll(func(key string, value *agent.AgentConfig) {
|
|
agents = append(agents, value)
|
|
})
|
|
return agents
|
|
}
|