From ab2addd893f0c1771487c45320f35ee81cb4a2e9 Mon Sep 17 00:00:00 2001 From: nullcat Date: Mon, 18 May 2026 04:25:30 +0800 Subject: [PATCH] fix(main): hostname not set --- core/config.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/core/config.go b/core/config.go index 7976b5c..9fecae0 100644 --- a/core/config.go +++ b/core/config.go @@ -51,20 +51,16 @@ type Config struct { } func LoadConfig(path string) (*Config, error) { - hostname, err := os.Hostname() - if err != nil { - hostname = "unknown" - } cfg := &Config{ Core: Core{ - Hostname: hostname, + Hostname: "", Ephemeral: true, AcceptRoutes: true, }, Forward: make(map[string][]ForwardRule), Connect: make(map[string][]ConnectRule), } - if _, err = os.Stat(path); err != nil { + if _, err := os.Stat(path); err != nil { // write a basic config buf := new(bytes.Buffer) err = toml.NewEncoder(buf).Encode(cfg) @@ -73,9 +69,18 @@ func LoadConfig(path string) (*Config, error) { } err = os.WriteFile(path, buf.Bytes(), 0644) } - _, err = toml.DecodeFile(path, cfg) + _, err := toml.DecodeFile(path, cfg) if err != nil { return nil, err } + + if cfg.Core.Hostname == "" { + hostname, err := os.Hostname() + if err != nil { + hostname = "unknown" + } + cfg.Core.Hostname = hostname + } + return cfg, nil }