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.

string.go 1.7 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. "math/rand"
  15. "regexp"
  16. "strings"
  17. "time"
  18. )
  19. const (
  20. CHARSET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  21. TIMEFORMAT = "20060102150405"
  22. )
  23. func RandomString(n int) string {
  24. sb := strings.Builder{}
  25. sb.Grow(n)
  26. for i := 0; i < n; i++ {
  27. sb.WriteByte(CHARSET[rand.Intn(len(CHARSET))])
  28. }
  29. return sb.String()
  30. }
  31. func TimeString() string {
  32. return time.Now().Format(TIMEFORMAT)
  33. }
  34. func IsValidHostAddress(input string) bool {
  35. //pattern := `^(([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+\.[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}):\d{1,5}$`
  36. pattern := `^((([a-zA-Z0-9]+\.)*[a-zA-Z0-9]+\.[a-zA-Z]{2,}|(\d{1,3}\.){3}\d{1,3}):\d{1,5})$|^.*\.com$`
  37. re, err := regexp.Compile(pattern)
  38. if err != nil {
  39. return false
  40. }
  41. return re.MatchString(input)
  42. }
  43. func MpaStringToInterface(m map[string]string) map[string]interface{} {
  44. result := make(map[string]interface{})
  45. for k, v := range m {
  46. result[k] = v
  47. }
  48. return result
  49. }
  50. func MapInterfaceToString(m map[string]interface{}) map[string]string {
  51. result := make(map[string]string)
  52. for k, v := range m {
  53. if str, ok := v.(string); ok {
  54. result[k] = str
  55. }
  56. }
  57. return result
  58. }

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.