mirror of
https://github.com/ScuroNeko/mtg.git
synced 2026-08-31 10:04:01 +03:00
FILE / ScuroNeko/mtg
internal/utils/read_config.go
Исходный файл и его история в репозитории.
97 lines
2.1 KiB
Go
97 lines
2.1 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"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.DC10002 {
|
|
ips = append(ips, addr.Value)
|
|
}
|
|
essentials.TelegramCoreAddresses[10002] = ips
|
|
}
|
|
if len(cfg.DCs.DC10003) > 0 {
|
|
var ips []string
|
|
for _, addr := range cfg.DCs.DC10003 {
|
|
ips = append(ips, addr.Value)
|
|
}
|
|
essentials.TelegramCoreAddresses[10003] = ips
|
|
}
|
|
}
|
|
|
|
func ReadConfig(path string) (*config.Config, error) {
|
|
content, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot read config file: %w", err)
|
|
}
|
|
|
|
conf, err := config.Parse(content)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("cannot parse config: %w", err)
|
|
}
|
|
|
|
if err := conf.Validate(); err != nil {
|
|
return nil, fmt.Errorf("invalid config: %w", err)
|
|
}
|
|
|
|
readCustomDC(conf)
|
|
|
|
return conf, nil
|
|
}
|