1
0

client_legacy_fields.go 709 B

123456789101112131415161718192021222324252627
  1. package model
  2. import (
  3. "strconv"
  4. "strings"
  5. )
  6. var legacyClientIntFields = []string{"tgId", "limitIp", "totalGB", "expiryTime", "reset", "created_at", "updated_at"}
  7. // NormalizeLegacyClientFields turns the string numbers older panels stored on a
  8. // client object into integers; an empty or unparseable value is dropped.
  9. func NormalizeLegacyClientFields(obj map[string]any) (changed bool) {
  10. for _, key := range legacyClientIntFields {
  11. s, ok := obj[key].(string)
  12. if !ok {
  13. continue
  14. }
  15. changed = true
  16. trimmed := strings.ReplaceAll(strings.TrimSpace(s), " ", "")
  17. if n, err := strconv.ParseInt(trimmed, 10, 64); err == nil {
  18. obj[key] = n
  19. } else {
  20. delete(obj, key)
  21. }
  22. }
  23. return changed
  24. }