aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorBobby <[email protected]>2025-04-06 08:50:11 +0530
committerBobby <[email protected]>2025-04-06 08:50:11 +0530
commitd706bd33c904c0f94c12aca17aae0fac82651576 (patch)
tree2dd554dcc0757991d4232cff60cdf2d1d8e734c1 /utils
parenta6de03acda17184f38103c2782ded6fb0ab768de (diff)
downloadmetachan-d706bd33c904c0f94c12aca17aae0fac82651576.tar.xz
metachan-d706bd33c904c0f94c12aca17aae0fac82651576.zip
syncing anime lists via fribb mappings
Diffstat (limited to 'utils')
-rw-r--r--utils/mappers/mappers.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/utils/mappers/mappers.go b/utils/mappers/mappers.go
new file mode 100644
index 0000000..d03150d
--- /dev/null
+++ b/utils/mappers/mappers.go
@@ -0,0 +1,47 @@
+package mappers
+
+import "strconv"
+
+func ForceString(s any) string {
+ switch v := s.(type) {
+ case string:
+ return v
+ case int:
+ return strconv.Itoa(v)
+ case int64:
+ return strconv.FormatInt(v, 10)
+ case float64:
+ return strconv.FormatFloat(v, 'f', -1, 64)
+ case bool:
+ if v {
+ return "true"
+ }
+ return "false"
+ default:
+ return ""
+ }
+}
+
+func ForceInt(s any) int {
+ switch v := s.(type) {
+ case string:
+ i, err := strconv.Atoi(v)
+ if err != nil {
+ return 0
+ }
+ return i
+ case int:
+ return v
+ case int64:
+ return int(v)
+ case float64:
+ return int(v)
+ case bool:
+ if v {
+ return 1
+ }
+ return 0
+ default:
+ return 0
+ }
+}