广告平台(媒体使用)
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

split_db.go 618 B

1 mese fa
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. }