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.

config.go 1.8 kB

2 years ago
2 years ago
2 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package utils
  2. import (
  3. "fmt"
  4. "regexp"
  5. "strconv"
  6. "github.com/beevik/etree"
  7. )
  8. type EcConfig struct {
  9. ecid string `xml:"ecid"`
  10. class string `xml:"class"`
  11. n int `xml:"n"`
  12. k int `xml:"k"`
  13. w int `xml:"w"`
  14. opt int `xml:"opt"`
  15. }
  16. func (r *EcConfig) GetK() int {
  17. return r.k
  18. }
  19. func (r *EcConfig) GetN() int {
  20. return r.n
  21. }
  22. func GetEcPolicy() *map[string]EcConfig {
  23. doc := etree.NewDocument()
  24. if err := doc.ReadFromFile("../confs/sysSetting.xml"); err != nil {
  25. panic(err)
  26. }
  27. ecMap := make(map[string]EcConfig, 20)
  28. root := doc.SelectElement("setting")
  29. for _, attr := range root.SelectElements("attribute") {
  30. if name := attr.SelectElement("name"); name.Text() == "ec.policy" {
  31. for _, eci := range attr.SelectElements("value") {
  32. tt := EcConfig{}
  33. tt.ecid = eci.SelectElement("ecid").Text()
  34. tt.class = eci.SelectElement("class").Text()
  35. tt.n, _ = strconv.Atoi(eci.SelectElement("n").Text())
  36. tt.k, _ = strconv.Atoi(eci.SelectElement("k").Text())
  37. tt.w, _ = strconv.Atoi(eci.SelectElement("w").Text())
  38. tt.opt, _ = strconv.Atoi(eci.SelectElement("opt").Text())
  39. ecMap[tt.ecid] = tt
  40. }
  41. }
  42. }
  43. fmt.Println(ecMap)
  44. return &ecMap
  45. //
  46. }
  47. func GetAgentIps() []string {
  48. doc := etree.NewDocument()
  49. if err := doc.ReadFromFile("../confs/sysSetting.xml"); err != nil {
  50. panic(err)
  51. }
  52. root := doc.SelectElement("setting")
  53. var ips []string // 定义存储 IP 的字符串切片
  54. for _, attr := range root.SelectElements("attribute") {
  55. if name := attr.SelectElement("name"); name.Text() == "agents.addr" {
  56. for _, ip := range attr.SelectElements("value") {
  57. ipRegex := regexp.MustCompile(`\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b`)
  58. match := ipRegex.FindString(ip.Text())
  59. print(match)
  60. ips = append(ips, match)
  61. }
  62. }
  63. }
  64. return ips
  65. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。