Skip to content

Commit 3b2c8f4

Browse files
chore: resolved-comments-1
1 parent 791fe85 commit 3b2c8f4

3 files changed

Lines changed: 333 additions & 332 deletions

File tree

constants/state_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ package constants
3838
// * Now these byte slices are parsed and converted into int64
3939
//
4040
// - Version 7: (Current Version) Fixed issues in Reformat.go: ReformatBool and ReformatValue
41-
// * Fixed boolean conversion for numeric inputs (int, int8, int16, int32, int64) in ReformatBool
41+
// * Fixed boolean conversion for numeric inputs (int8, int16, int32, int64) in ReformatBool
4242
// * Fixed float32 and float64 string conversion ("%d" → "%v") in ReformatValue
4343

4444
const (

utils/typeutils/reformat.go

Lines changed: 10 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import (
1717
"go.mongodb.org/mongo-driver/bson/primitive"
1818
)
1919

20-
type StringInterface interface {
21-
String() string
22-
}
23-
2420
var (
2521
ErrNullValue = fmt.Errorf("null value")
2622
)
@@ -44,16 +40,6 @@ var DateTimeFormats = []string{
4440

4541
var GeospatialTypes = []string{"geometry", "point", "polygon", "linestring", "multi"}
4642

47-
func getFirstNotNullType(datatypes []types.DataType) types.DataType {
48-
for _, datatype := range datatypes {
49-
if datatype != types.Null {
50-
return datatype
51-
}
52-
}
53-
54-
return types.Null
55-
}
56-
5743
func ReformatRecord(fields Fields, record types.Record) error {
5844
for key, val := range record {
5945
field, found := fields[key]
@@ -70,10 +56,6 @@ func ReformatRecord(fields Fields, record types.Record) error {
7056
return nil
7157
}
7258

73-
func ReformatValueOnDataTypes(datatypes []types.DataType, v any) (any, error) {
74-
return ReformatValue(getFirstNotNullType(datatypes), v)
75-
}
76-
7759
func ReformatValue(dataType types.DataType, v any) (any, error) {
7860
if v == nil {
7961
return v, nil
@@ -96,7 +78,7 @@ func ReformatValue(dataType types.DataType, v any) (any, error) {
9678
case uint, uint8, uint16, uint32, uint64:
9779
return fmt.Sprintf("%d", v), nil
9880
case float32, float64:
99-
// Fixed float string conversion (%v) for v>6; older versions retain %d for backward compatibility
81+
// Fixed float string conversion (%v) for version > 6; older versions retain %d for backward compatibility
10082
if constants.LoadedStateVersion > 6 {
10183
return fmt.Sprintf("%v", v), nil
10284
}
@@ -149,7 +131,7 @@ func ReformatBool(v interface{}) (bool, error) {
149131
return false, nil
150132
}
151133
case int, int16, int32, int64, int8:
152-
// Fixed int8/int16/int32/int64 bool handling for v>6; older versions keep strict comparison
134+
// Fixed int8/int16/int32/int64 bool handling for version>6; older versions keep strict comparison
153135
if constants.LoadedStateVersion > 6 {
154136
switch reflect.ValueOf(booleanValue).Int() {
155137
case 1:
@@ -159,15 +141,14 @@ func ReformatBool(v interface{}) (bool, error) {
159141
default:
160142
return false, fmt.Errorf("found to be boolean, but value is not boolean : %v", v)
161143
}
162-
} else {
163-
switch booleanValue {
164-
case 1:
165-
return true, nil
166-
case 0:
167-
return false, nil
168-
default:
169-
return false, fmt.Errorf("found to be boolean, but value is not boolean : %v", v)
170-
}
144+
}
145+
switch booleanValue {
146+
case 1:
147+
return true, nil
148+
case 0:
149+
return false, nil
150+
default:
151+
return false, fmt.Errorf("found to be boolean, but value is not boolean : %v", v)
171152
}
172153
default:
173154
return false, fmt.Errorf("found to be boolean, but value is not boolean : %v", v)
@@ -543,39 +524,6 @@ func ReformatFloat32(v interface{}) (float32, error) {
543524
return float32(0), fmt.Errorf("failed to change %v (type:%T) to float32", v, v)
544525
}
545526

546-
func ReformatByteArraysToString(data map[string]any) map[string]any {
547-
for key, value := range data {
548-
switch value := value.(type) {
549-
case map[string]any:
550-
data[key] = ReformatByteArraysToString(value)
551-
case []byte:
552-
data[key] = string(value)
553-
case []map[string]any:
554-
decryptedArray := []map[string]any{}
555-
for _, element := range value {
556-
decryptedArray = append(decryptedArray, ReformatByteArraysToString(element))
557-
}
558-
559-
data[key] = decryptedArray
560-
case []any:
561-
decryptedArray := []any{}
562-
for _, element := range value {
563-
switch element := element.(type) {
564-
case map[string]any:
565-
decryptedArray = append(decryptedArray, ReformatByteArraysToString(element))
566-
case []byte:
567-
decryptedArray = append(decryptedArray, string(element))
568-
default:
569-
decryptedArray = append(decryptedArray, element)
570-
}
571-
}
572-
573-
data[key] = decryptedArray
574-
}
575-
}
576-
return data
577-
}
578-
579527
func ReformatGeoType(v any) (any, error) {
580528
if v == nil {
581529
return nil, ErrNullValue

0 commit comments

Comments
 (0)