conversion.go 1015 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package utils
  2. import jsoniter "github.com/json-iterator/go"
  3. func Convertion(dest map[string]interface{}, source string) {
  4. s := make(map[string]interface{})
  5. err := jsoniter.UnmarshalFromString(source, &s)
  6. if err != nil {
  7. return
  8. }
  9. for k, v := range s {
  10. // TODO 字段检查是否合规
  11. // 判断是否非生产环境,非生产环境检查
  12. if value, ok := dest[k]; ok {
  13. if _, ok = value.(string); ok && value.(string) == "" {
  14. dest[k] = v
  15. }
  16. /*if value == "" {
  17. dest[k] = v
  18. }*/
  19. } else {
  20. dest[k] = v
  21. }
  22. }
  23. return
  24. }
  25. // 覆盖
  26. func ConvertionCover(dest map[string]interface{}, source string) {
  27. s := make(map[string]interface{})
  28. err := jsoniter.UnmarshalFromString(source, &s)
  29. if err != nil {
  30. return
  31. }
  32. for k, v := range s {
  33. dest[k] = v
  34. }
  35. return
  36. }
  37. func GetInterfaceString(dest map[string]interface{}, key string) string {
  38. if value, ok := dest[key]; ok {
  39. if ret, ok := value.(string); ok {
  40. return ret
  41. }
  42. /*if value == "" {
  43. dest[k] = v
  44. }*/
  45. }
  46. return ""
  47. }