diff --git a/internal/config/config.go b/internal/config/config.go index d9653a8..56b57d5 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -1,6 +1,7 @@ package config import ( + "fmt" "os" "ssender/internal/models" @@ -22,9 +23,20 @@ func NewConfig(configPath string) (*models.Config, error) { d := yaml.NewDecoder(file) // Start YAML decoding from file - if err := d.Decode(&config); err != nil { + if err := d.Decode(config); err != nil { return nil, err } + // Validate required fields + if config.Dbpath == "" { + return nil, fmt.Errorf("dbpath is required in config") + } + if config.Telegram.Send && (config.Telegram.Token == "" || config.Telegram.ChatId == 0) { + return nil, fmt.Errorf("telegram token and chatid are required when send is enabled") + } + if config.VK.Send && (config.VK.Token == "" || config.VK.OwnerId == 0) { + return nil, fmt.Errorf("vk token and ownerid are required when send is enabled") + } + return config, nil }