mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 19:04:02 +03:00
support for test dc1-3
loading custom dc ips from config
This commit is contained in:
@@ -91,6 +91,17 @@ type Config struct {
|
||||
MetricPrefix TypeMetricPrefix `json:"metricPrefix"`
|
||||
} `json:"prometheus"`
|
||||
} `json:"stats"`
|
||||
DCs struct{
|
||||
DC1 []TypeHostPort `json:"dc1"`
|
||||
DC2 []TypeHostPort `json:"dc2"`
|
||||
DC3 []TypeHostPort `json:"dc3"`
|
||||
DC4 []TypeHostPort `json:"dc4"`
|
||||
DC5 []TypeHostPort `json:"dc5"`
|
||||
DC203 []TypeHostPort `json:"dc203"`
|
||||
DC10001 []TypeHostPort `json:"dc10001"`
|
||||
DC10002[]TypeHostPort `json:"dc10002"`
|
||||
DC10003 []TypeHostPort `json:"dc10003"`
|
||||
} `json:"dc"`
|
||||
}
|
||||
|
||||
func (c *Config) GetConcurrency(defaultValue uint) uint {
|
||||
|
||||
@@ -84,6 +84,17 @@ type tomlConfig struct {
|
||||
MetricPrefix string `toml:"metric-prefix" json:"metricPrefix,omitempty"`
|
||||
} `toml:"prometheus" json:"prometheus,omitempty"`
|
||||
} `toml:"stats" json:"stats,omitempty"`
|
||||
DCs struct{
|
||||
DC1 []string `toml:"dc1" json:"dc1,omitempty"`
|
||||
DC2 []string `toml:"dc2" json:"dc2,omitempty"`
|
||||
DC3 []string `toml:"dc3" json:"dc3,omitempty"`
|
||||
DC4 []string `toml:"dc4" json:"dc4,omitempty"`
|
||||
DC5 []string `toml:"dc5" json:"dc5,omitempty"`
|
||||
DC203 []string `toml:"dc203" json:"dc203,omitempty"`
|
||||
DC10001 []string `toml:"dc10001" json:"dc10001,omitempty"`
|
||||
DC10002 []string `toml:"dc10002" json:"dc10002,omitempty"`
|
||||
DC10003 []string `toml:"dc10003" json:"dc10003,omitempty"`
|
||||
} `toml:"dc" json:"dc,omitempty"`
|
||||
}
|
||||
|
||||
func Parse(rawData []byte) (*Config, error) {
|
||||
|
||||
@@ -2,11 +2,82 @@ package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/9seconds/mtg/v2/essentials"
|
||||
"github.com/9seconds/mtg/v2/internal/config"
|
||||
)
|
||||
|
||||
func readCustomDC(cfg *config.Config) {
|
||||
if len(cfg.DCs.DC1) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC1 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[1] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC2) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC2 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[2] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC3) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC3 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[3] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC4) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC4 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[4] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC5) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC5 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[5] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC203) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC203 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[203] = ips
|
||||
}
|
||||
|
||||
if len(cfg.DCs.DC10001) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC10001 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[10001] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC10002) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC203 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[10002] = ips
|
||||
}
|
||||
if len(cfg.DCs.DC10003) > 0 {
|
||||
var ips []string
|
||||
for _, addr := range cfg.DCs.DC203 {
|
||||
ips = append(ips, addr.Value)
|
||||
}
|
||||
essentials.TelegramCoreAddresses[10003] = ips
|
||||
}
|
||||
log.Println(essentials.TelegramCoreAddresses)
|
||||
log.Println(cfg.DCs)
|
||||
}
|
||||
|
||||
func ReadConfig(path string) (*config.Config, error) {
|
||||
content, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
@@ -21,6 +92,7 @@ func ReadConfig(path string) (*config.Config, error) {
|
||||
if err := conf.Validate(); err != nil {
|
||||
return nil, fmt.Errorf("invalid config: %w", err)
|
||||
}
|
||||
readCustomDC(conf)
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user