feat: add characters

This commit is contained in:
2026-07-10 00:56:03 +03:30
parent da6df0328f
commit fe0b63083c
19 changed files with 635 additions and 92 deletions
+37
View File
@@ -0,0 +1,37 @@
package admin
import (
"strconv"
"strings"
)
// flexBool یک bool است که هنگامِ decode از JSON، مقادیرِ عددی/رشته‌ای را هم می‌پذیرد
// (true/false، 0/1، "1"/"true"). دلیل: SQLite بولین‌ها را int برمی‌گرداند و پنل
// همان مقدار را دوباره می‌فرستد؛ decodeِ سخت‌گیرِ Go عدد را در bool نمی‌پذیرد → 400.
type flexBool bool
func (f *flexBool) UnmarshalJSON(b []byte) error {
s := strings.Trim(strings.TrimSpace(string(b)), `"`)
*f = s == "1" || s == "true" || s == "1.0"
return nil
}
// flexInt یک int64 است که از عدد، رشته‌ی عددی، خالی یا null هم decode می‌شود
// (تا ورودی‌های متنیِ عددی مثلِ "2000" باعثِ 400 نشوند).
type flexInt int64
func (f *flexInt) UnmarshalJSON(b []byte) error {
s := strings.Trim(strings.TrimSpace(string(b)), `"`)
if s == "" || s == "null" {
*f = 0
return nil
}
v, err := strconv.ParseFloat(s, 64) // "2000" و "2000.0" هر دو
if err != nil {
return err
}
*f = flexInt(int64(v))
return nil
}
func (f flexInt) i() int64 { return int64(f) }