You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

copier.go 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright (c) [2023] [pcm]
  3. [pcm-coordinator] is licensed under Mulan PSL v2.
  4. You can use this software according to the terms and conditions of the Mulan PSL v2.
  5. You may obtain a copy of Mulan PSL v2 at:
  6. http://license.coscl.org.cn/MulanPSL2
  7. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  8. EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  9. MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  10. See the Mulan PSL v2 for more details.
  11. */
  12. package utils
  13. import (
  14. "github.com/jinzhu/copier"
  15. "github.com/pkg/errors"
  16. "strconv"
  17. "time"
  18. )
  19. var Converters = []copier.TypeConverter{
  20. {
  21. SrcType: time.Time{},
  22. DstType: copier.String,
  23. Fn: func(src interface{}) (interface{}, error) {
  24. s, ok := src.(time.Time)
  25. if !ok {
  26. return nil, errors.New("src type not matching")
  27. }
  28. return s.Format(time.RFC3339), nil
  29. },
  30. },
  31. {
  32. SrcType: copier.String,
  33. DstType: copier.Int,
  34. Fn: func(src interface{}) (interface{}, error) {
  35. s, ok := src.(string)
  36. if !ok {
  37. return nil, errors.New("src type not matching")
  38. }
  39. return strconv.Atoi(s)
  40. },
  41. },
  42. {
  43. SrcType: copier.String,
  44. DstType: copier.Bool,
  45. Fn: func(src interface{}) (interface{}, error) {
  46. s, ok := src.(string)
  47. if !ok {
  48. return nil, errors.New("src type not matching")
  49. }
  50. return strconv.ParseBool(s)
  51. },
  52. },
  53. }

PCM is positioned as Software stack over Cloud, aiming to build the standards and ecology of heterogeneous cloud collaboration for JCC in a non intrusive and autonomous peer-to-peer manner.