From a0828a265f23cc8c450f9d78b8cde05b6a8adfc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=80=85=E5=B0=8F=E8=93=9D?= <540590988@qq.com> Date: Fri, 5 Jul 2019 16:18:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=8E=B7=E5=8F=96hostname=E7=9A=84?= =?UTF-8?q?=E4=BC=98=E5=85=88=E7=BA=A7=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/conf/env/env.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/conf/env/env.go b/pkg/conf/env/env.go index 54b867e6d..64c4a963a 100644 --- a/pkg/conf/env/env.go +++ b/pkg/conf/env/env.go @@ -45,10 +45,13 @@ var ( func init() { var err error - if Hostname, err = os.Hostname(); err != nil || Hostname == "" { - Hostname = os.Getenv("HOSTNAME") + Hostname = os.Getenv("HOSTNAME") + if Hostname == "" { + Hostname, err = os.Hostname() + if err != nil { + Hostname = "" + } } - addFlag(flag.CommandLine) }