53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
/**
|
|
* @brief Структура конфигурации приложения
|
|
*/
|
|
type Config struct {
|
|
App struct {
|
|
Name string `toml:"name"`
|
|
MaxLoginAttempts int `toml:"max_login_attempts"`
|
|
LockTimeoutSec int `toml:"lock_timeout_sec"`
|
|
} `toml:"app"`
|
|
|
|
Database struct {
|
|
Type string `toml:"type"`
|
|
Path string `toml:"path"`
|
|
} `toml:"database"`
|
|
|
|
Security struct {
|
|
PasswordHash string `toml:"password_hash"`
|
|
} `toml:"security"`
|
|
|
|
UI struct {
|
|
ShowWelcome bool `toml:"show_welcome"`
|
|
} `toml:"ui"`
|
|
}
|
|
|
|
/**
|
|
* @brief Загрузка конфигурации из TOML файла
|
|
*
|
|
* @param path путь к файлу конфигурации
|
|
* @return cfg указатель на структуру Config
|
|
* @return error ошибка при загрузке
|
|
*/
|
|
func Load(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var cfg Config
|
|
err = toml.Unmarshal(data, &cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &cfg, nil
|
|
}
|