feat: first working version
This commit is contained in:
parent
a67e208d6e
commit
1029563cb1
11 changed files with 585 additions and 0 deletions
53
internal/config/config.go
Normal file
53
internal/config/config.go
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue