修复自定义Marshal序列化的BUG
This commit is contained in:
		
							
								
								
									
										10
									
								
								data_type.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								file_type.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								logger.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								logger_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								logger_test.go
									
									
									
									
									
										Normal file
									
								
							@ -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)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										6
									
								
								redis.go
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								request.go
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								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
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user