From 433fcc19d021696ec196b3129b59e8149e413149 Mon Sep 17 00:00:00 2001 From: simonzhangsz Date: Wed, 20 Dec 2023 16:56:35 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=BB=98=E8=AE=A4=E5=90=AF=E5=8A=A8loca?= =?UTF-8?q?lhost=E4=BE=A6=E5=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- restagent/restagent.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/restagent/restagent.go b/restagent/restagent.go index 8e935593..3cfdce66 100644 --- a/restagent/restagent.go +++ b/restagent/restagent.go @@ -197,6 +197,17 @@ func main() { } else { go HttpListen(listen, app) } + } else if rest.IPv4 != "0.0.0.0" { + // 默认启动localhost侦听 + listenLocal := "127.0.0.1" + ":" + strconv.Itoa(int(rest.Port)) + listenv6Local := "[" + "::1" + "]" + ":" + strconv.Itoa(int(rest.Port)) + if strings.ToLower(rest.Scheme) == "https" { + go HttpListenTLS(listenLocal, rest.CaFile, rest.CertFile, rest.KeyFile, app) + go HttpListenTLS(listenv6Local, rest.CaFile, rest.CertFile, rest.KeyFile, app) + } else { + go HttpListen(listenLocal, app) + go HttpListen(listenv6Local, app) + } } // ipv6 goroutines if rest.IPv6 != "" { @@ -206,18 +217,19 @@ func main() { } else { go HttpListen(listenv6, app) } + } else if rest.IPv6 != "::" { + // 默认启动localhost侦听 + listenLocal := "127.0.0.1" + ":" + strconv.Itoa(int(rest.Port)) + listenv6Local := "[" + "::1" + "]" + ":" + strconv.Itoa(int(rest.Port)) + if strings.ToLower(rest.Scheme) == "https" { + go HttpListenTLS(listenLocal, rest.CaFile, rest.CertFile, rest.KeyFile, app) + go HttpListenTLS(listenv6Local, rest.CaFile, rest.CertFile, rest.KeyFile, app) + } else { + go HttpListen(listenLocal, app) + go HttpListen(listenv6Local, app) + } } - // 默认启动localhost侦听 - listenLocal := "127.0.0.1" + ":" + strconv.Itoa(int(rest.Port)) - listenv6Local := "[" + "::1" + "]" + ":" + strconv.Itoa(int(rest.Port)) - if strings.ToLower(rest.Scheme) == "https" { - go HttpListenTLS(listenLocal, rest.CaFile, rest.CertFile, rest.KeyFile, app) - go HttpListenTLS(listenv6Local, rest.CaFile, rest.CertFile, rest.KeyFile, app) - } else { - go HttpListen(listenLocal, app) - go HttpListen(listenv6Local, app) - } } if conf.WebServer.Enabled {