From 3c988693b5d6639f26889129639d48bb4c5cd413 Mon Sep 17 00:00:00 2001 From: database64128 Date: Thu, 17 Dec 2020 05:03:26 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=95=B3=20Prevent=20trailing=20whitespaces?= =?UTF-8?q?=20in=20logs=20(#526)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/log/access.go | 16 ++++++++++------ common/serial/string.go | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/log/access.go b/common/log/access.go index f3398b55f..789426d92 100644 --- a/common/log/access.go +++ b/common/log/access.go @@ -36,19 +36,23 @@ func (m *AccessMessage) String() string { builder.WriteString(string(m.Status)) builder.WriteByte(' ') builder.WriteString(serial.ToString(m.To)) - builder.WriteByte(' ') + if len(m.Detour) > 0 { - builder.WriteByte('[') + builder.WriteString(" [") builder.WriteString(m.Detour) - builder.WriteString("] ") + builder.WriteByte(']') + } + + if reason := serial.ToString(m.Reason); len(reason) > 0 { + builder.WriteString(" ") + builder.WriteString(reason) } - builder.WriteString(serial.ToString(m.Reason)) if len(m.Email) > 0 { - builder.WriteString("email:") + builder.WriteString(" email: ") builder.WriteString(m.Email) - builder.WriteByte(' ') } + return builder.String() } diff --git a/common/serial/string.go b/common/serial/string.go index 70de87a76..e220e543a 100644 --- a/common/serial/string.go +++ b/common/serial/string.go @@ -8,7 +8,7 @@ import ( // ToString serialize an arbitrary value into string. func ToString(v interface{}) string { if v == nil { - return " " + return "" } switch value := v.(type) {