From cf7c7cb392070d44361d815f039840e0b27ec8aa Mon Sep 17 00:00:00 2001 From: Fyn <53678344+fynxiu@users.noreply.github.com> Date: Mon, 28 Feb 2022 17:31:59 +0800 Subject: [PATCH] build: update goctl dependency ddl-parser to v1.0.3 (#1586) * build: update goctl dependency ddl-parser to v1.0.3 * fix: race condition when testing logx Resolves: #1587 --- core/logx/logs.go | 10 +++++++--- core/logx/tracelogger_test.go | 4 ++-- tools/goctl/go.mod | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/core/logx/logs.go b/core/logx/logs.go index 34bb1112..81ee4e3e 100644 --- a/core/logx/logs.go +++ b/core/logx/logs.go @@ -33,7 +33,7 @@ const ( ) const ( - jsonEncodingType = iota + jsonEncodingType uint32 = iota plainEncodingType jsonEncoding = "json" @@ -137,9 +137,9 @@ func SetUp(c LogConf) error { } switch c.Encoding { case plainEncoding: - encoding = plainEncodingType + setEncoding(plainEncodingType) default: - encoding = jsonEncodingType + setEncoding(jsonEncodingType) } switch c.Mode { @@ -666,3 +666,7 @@ func (lw logWriter) Write(data []byte) (int, error) { lw.logger.Print(string(data)) return len(data), nil } + +func setEncoding(encodingType uint32) { + atomic.StoreUint32(&encoding, encodingType) +} diff --git a/core/logx/tracelogger_test.go b/core/logx/tracelogger_test.go index 7da8d0dd..1427e736 100644 --- a/core/logx/tracelogger_test.go +++ b/core/logx/tracelogger_test.go @@ -84,9 +84,9 @@ func TestTraceInfo(t *testing.T) { func TestTraceInfoConsole(t *testing.T) { old := encoding - encoding = plainEncodingType + setEncoding(jsonEncodingType) defer func() { - encoding = old + setEncoding(old) }() var buf mockWriter diff --git a/tools/goctl/go.mod b/tools/goctl/go.mod index 5e4ffd7f..9adc3c44 100644 --- a/tools/goctl/go.mod +++ b/tools/goctl/go.mod @@ -12,6 +12,6 @@ require ( github.com/stretchr/testify v1.7.0 github.com/urfave/cli v1.22.5 github.com/zeromicro/antlr v0.0.1 - github.com/zeromicro/ddl-parser v1.0.2 + github.com/zeromicro/ddl-parser v1.0.3 github.com/zeromicro/go-zero v1.3.0 )