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 }