change default agent name to hostname

This commit is contained in:
yusing 2025-02-10 10:48:58 +08:00
parent 58ea9750d7
commit 9120bbea34
2 changed files with 16 additions and 4 deletions

View file

@ -5,8 +5,8 @@ services:
restart: always
network_mode: host # do not change this
environment:
GODOXY_AGENT_NAME: "agent-1"
GODOXY_AGENT_PORT: "8890"
GODOXY_AGENT_NAME: # defaults to hostname
GODOXY_AGENT_PORT: # defaults to 8890
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./certs:/app/certs # store Agent CA cert and Agent SSL cert

16
agent/pkg/env/env.go vendored
View file

@ -1,8 +1,20 @@
package env
import "github.com/yusing/go-proxy/internal/common"
import (
"os"
"github.com/yusing/go-proxy/internal/common"
)
func DefaultAgentName() string {
name, err := os.Hostname()
if err != nil {
return "agent"
}
return name
}
var (
AgentName = common.GetEnvString("AGENT_NAME", "agent")
AgentName = common.GetEnvString("AGENT_NAME", DefaultAgentName())
AgentPort = common.GetEnvInt("AGENT_PORT", 8890)
)