mark.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package ddm
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func (m Mobile) MarshalJSON() ([]byte, error) {
  7. if len(m) != 11 {
  8. return []byte(`"` + m + `"`), nil
  9. }
  10. v := fmt.Sprintf("%s****%s", m[:3], m[len(m)-4:])
  11. return []byte(`"` + v + `"`), nil
  12. }
  13. func (bc BankCard) MarshalJSON() ([]byte, error) {
  14. if len(bc) > 19 || len(bc) < 16 {
  15. return []byte(`"` + bc + `"`), nil
  16. }
  17. v := fmt.Sprintf("%s******%s", bc[:6], bc[len(bc)-4:])
  18. return []byte(`"` + v + `"`), nil
  19. }
  20. func (card IDCard) MarshalJSON() ([]byte, error) {
  21. if len(card) != 18 {
  22. return []byte(`"` + card + `"`), nil
  23. }
  24. v := fmt.Sprintf("%s******%s", card[:1], card[len(card)-1:])
  25. return []byte(`"` + v + `"`), nil
  26. }
  27. func (name IDName) MarshalJSON() ([]byte, error) {
  28. if len(name) < 1 {
  29. return []byte(`""`), nil
  30. }
  31. nameRune := []rune(name)
  32. v := fmt.Sprintf("*%s", string(nameRune[1:]))
  33. return []byte(`"` + v + `"`), nil
  34. }
  35. func (pw PassWord) MarshalJSON() ([]byte, error) {
  36. v := "******"
  37. return []byte(`"` + v + `"`), nil
  38. }
  39. func (e Email) MarshalJSON() ([]byte, error) {
  40. if !strings.Contains(string(e), "@") {
  41. return []byte(`"` + e + `"`), nil
  42. }
  43. split := strings.Split(string(e), "@")
  44. if len(split[0]) < 1 || len(split[1]) < 1 {
  45. return []byte(`"` + e + `"`), nil
  46. }
  47. v := fmt.Sprintf("%s***%s", split[0][:1], split[0][len(split[0])-1:])
  48. return []byte(`"` + v + "@" + split[1] + `"`), nil
  49. }