2023-11-17 20:34:20 +05:00
|
|
|
|
package main
|
|
|
|
|
|
2023-11-20 20:34:09 +05:00
|
|
|
|
import (
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
go_ora "github.com/sijms/go-ora/v2"
|
|
|
|
|
"gopkg.in/ini.v1"
|
|
|
|
|
)
|
|
|
|
|
|
2023-11-17 20:34:20 +05:00
|
|
|
|
// Server - экземпляр сервера
|
|
|
|
|
type Server struct {
|
|
|
|
|
// Полная ссылка на БД, вкючая логин/пароль
|
|
|
|
|
Url string
|
2023-11-20 20:34:09 +05:00
|
|
|
|
|
2023-11-17 20:34:20 +05:00
|
|
|
|
// Наименование филиала
|
|
|
|
|
Name string
|
2023-11-20 20:34:09 +05:00
|
|
|
|
|
|
|
|
|
// Статус работы с сервером
|
|
|
|
|
Status string
|
|
|
|
|
|
|
|
|
|
// Ошибка работы с сервером
|
|
|
|
|
Error error
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// loadConfig считывает конфиг и возвращает список параметров серверов
|
|
|
|
|
func loadConfig(filePath string) ([]Server, error) {
|
|
|
|
|
servers := make([]Server, 0)
|
|
|
|
|
|
|
|
|
|
iniBytes, err := readFileIgnoreBOM(filePath)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg, err := ini.Load(iniBytes)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cfg.DeleteSection("DEFAULT")
|
|
|
|
|
|
|
|
|
|
for _, server := range cfg.SectionStrings() {
|
|
|
|
|
loginKey, err := cfg.Section(server).GetKey("Login")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
passwordKey, err := cfg.Section(server).GetKey("Password")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nameKey, err := cfg.Section(server).GetKey("Name")
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
serv := strings.Split(server, "/")[0]
|
|
|
|
|
service := strings.Split(server, "/")[1]
|
|
|
|
|
dbUrl := go_ora.BuildUrl(serv, 1521, service, loginKey.String(), passwordKey.String(), map[string]string{"TIMEOUT": "0", "PREFETCH_ROWS": "1000"})
|
|
|
|
|
|
|
|
|
|
server := Server{
|
|
|
|
|
Url: dbUrl,
|
|
|
|
|
Name: nameKey.String()}
|
|
|
|
|
|
|
|
|
|
servers = append(servers, server)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return servers, nil
|
2023-11-17 20:34:20 +05:00
|
|
|
|
}
|