From 10759d9c5ee81ce4a368ceefb53055b8ccb91f29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 22 Jan 2025 15:55:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89Ma?= =?UTF-8?q?rshal=E5=BA=8F=E5=88=97=E5=8C=96=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_type.go | 10 +++++----- file_type.go | 10 +++++----- header.go | 6 +++--- logger.go | 10 +++++----- logger_test.go | 19 +++++++++++++++++++ redis.go | 6 +++--- request.go | 10 +++++----- scheme.go | 6 +++--- 8 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 logger_test.go diff --git a/data_type.go b/data_type.go index 273d02b..ec737e0 100644 --- a/data_type.go +++ b/data_type.go @@ -14,11 +14,11 @@ package consts // Date : 14:10 2024/11/25 type DataType string -func (df DataType) String() string { - return string(df) +func (df *DataType) String() string { + return string(*df) } -func (df DataType) MarshalJSON() ([]byte, error) { +func (df *DataType) MarshalJSON() ([]byte, error) { return []byte(df.String()), nil } @@ -27,9 +27,9 @@ func (df DataType) MarshalJSON() ([]byte, error) { // Author : go_developer@163.com<白茶清欢> // // Date : 14:45 2024/11/25 -func (df DataType) IsValid() bool { +func (df *DataType) IsValid() bool { for _, item := range DataTypeList { - if item.Value == df { + if item.Value == *df { return true } } diff --git a/file_type.go b/file_type.go index 73977d5..3db8248 100644 --- a/file_type.go +++ b/file_type.go @@ -9,15 +9,15 @@ package consts type FileType string -func (ft FileType) String() string { - return string(ft) +func (ft *FileType) String() string { + return string(*ft) } -func (ft FileType) MarshalJSON() ([]byte, error) { +func (ft *FileType) MarshalJSON() ([]byte, error) { return []byte(ft.String()), nil } -func (ft FileType) IsValid() bool { +func (ft *FileType) IsValid() bool { supportFileTypeList := []FileType{ FileTypeJson, FileTypeIni, @@ -28,7 +28,7 @@ func (ft FileType) IsValid() bool { FileTypeTxt, } for _, fileType := range supportFileTypeList { - if fileType == ft { + if fileType == *ft { return true } } diff --git a/header.go b/header.go index d0b9577..94f0697 100644 --- a/header.go +++ b/header.go @@ -9,11 +9,11 @@ package consts type HttpHeader string -func (hh HttpHeader) String() string { - return string(hh) +func (hh *HttpHeader) String() string { + return string(*hh) } -func (hh HttpHeader) MarshalJSON() ([]byte, error) { +func (hh *HttpHeader) MarshalJSON() ([]byte, error) { return []byte(hh.String()), nil } diff --git a/logger.go b/logger.go index d6dc67c..f55b9a6 100644 --- a/logger.go +++ b/logger.go @@ -9,15 +9,15 @@ package consts type LogLevel string -func (ll LogLevel) String() string { - return string(ll) +func (ll *LogLevel) String() string { + return string(*ll) } -func (ll LogLevel) MarshalJSON() ([]byte, error) { +func (ll *LogLevel) MarshalJSON() ([]byte, error) { return []byte(ll.String()), nil } -func (ll LogLevel) IsValid() bool { +func (ll *LogLevel) IsValid() bool { levelList := []LogLevel{ LogLevelDebug, LogLevelInfo, @@ -26,7 +26,7 @@ func (ll LogLevel) IsValid() bool { LogLevelPanic, } for _, level := range levelList { - if level == ll { + if level == *ll { return true } } diff --git a/logger_test.go b/logger_test.go new file mode 100644 index 0000000..baafa04 --- /dev/null +++ b/logger_test.go @@ -0,0 +1,19 @@ +// Package consts ... +// +// Description : consts ... +// +// Author : go_developer@163.com<白茶清欢> +// +// Date : 2025-01-22 15:36 +package consts + +import ( + "encoding/json" + "fmt" + "testing" +) + +func TestLogLevel_String(t *testing.T) { + byteData, err := json.Marshal(LogLevelDebug) + fmt.Println(string(byteData), err) +} diff --git a/redis.go b/redis.go index cb98ec6..dedf955 100644 --- a/redis.go +++ b/redis.go @@ -9,11 +9,11 @@ package consts type RedisCmd string -func (rc RedisCmd) String() string { - return string(rc) +func (rc *RedisCmd) String() string { + return string(*rc) } -func (rc RedisCmd) MarshalJSON() ([]byte, error) { +func (rc *RedisCmd) MarshalJSON() ([]byte, error) { return []byte(rc.String()), nil } diff --git a/request.go b/request.go index efcedc1..6b79f49 100644 --- a/request.go +++ b/request.go @@ -38,17 +38,17 @@ func (rdl RequestDataLocation) IsValid() bool { // Date : 14:41 2024/11/25 type ResponseDataLocation string -func (rdl ResponseDataLocation) String() string { - return string(rdl) +func (rdl *ResponseDataLocation) String() string { + return string(*rdl) } -func (rdl ResponseDataLocation) MarshalJSON() ([]byte, error) { +func (rdl *ResponseDataLocation) MarshalJSON() ([]byte, error) { return []byte(rdl.String()), nil } -func (rdl ResponseDataLocation) IsValid() bool { +func (rdl *ResponseDataLocation) IsValid() bool { for _, item := range ResponseDataLocationList { - if item.Value == rdl { + if item.Value == *rdl { return true } } diff --git a/scheme.go b/scheme.go index fda9a86..bfdbe2f 100644 --- a/scheme.go +++ b/scheme.go @@ -9,11 +9,11 @@ package consts type HttpScheme string -func (hs HttpScheme) String() string { - return string(hs) +func (hs *HttpScheme) String() string { + return string(*hs) } -func (hs HttpScheme) MarshalJSON() ([]byte, error) { +func (hs *HttpScheme) MarshalJSON() ([]byte, error) { return []byte(hs.String()), nil } -- 2.36.6