refactoring

This commit is contained in:
2025-07-13 06:59:56 +02:00
parent a9f66c9f70
commit 63284ab51c
25 changed files with 158 additions and 105 deletions

View File

@@ -0,0 +1,37 @@
package stateVariables
import (
"fmt"
)
// toString converts v to string if possible.
func toString(v interface{}) (string, error) {
switch val := v.(type) {
case string:
return val, nil
case []byte:
return string(val), nil
case fmt.Stringer:
return val.String(), nil
case int, int8, int16, int32, int64:
return fmt.Sprintf("%d", val), nil
case uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", val), nil
case float32, float64:
return fmt.Sprintf("%v", val), nil
case bool:
if val {
return "true", nil
}
return "false", nil
default:
return "", fmt.Errorf("cannot convert type %T to string", v)
}
}