广告平台(媒体使用)
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

3 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. package md
  2. import (
  3. "regexp"
  4. "xorm.io/xorm"
  5. )
  6. type DbInfo struct {
  7. User string
  8. Psw string
  9. Name string
  10. Host string
  11. }
  12. func SplitDbInfo(eg *xorm.Engine) *DbInfo {
  13. if eg == nil {
  14. return &DbInfo{
  15. User: "nil",
  16. Psw: "nil",
  17. Host: "nil",
  18. Name: "nil",
  19. }
  20. }
  21. pattern := `(\w+):(.*)@tcp\(([\w\.\-\:\_]+)\)\/(\w+)`
  22. reg := regexp.MustCompile(pattern).FindStringSubmatch(eg.DataSourceName())
  23. if len(reg) < 5 {
  24. return &DbInfo{
  25. User: "unknown",
  26. Psw: "unknown",
  27. Host: "unknown",
  28. Name: "unknown",
  29. }
  30. }
  31. return &DbInfo{
  32. User: reg[1],
  33. Psw: reg[2],
  34. Host: reg[3],
  35. Name: reg[4],
  36. }
  37. }