广告平台(站长下代理使用)
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

split_db.go 618 B

il y a 1 mois
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. }