|
|
|
|
@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
|
|
|
|
|
package config |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
"fmt" |
|
|
|
|
"os" |
|
|
|
|
"ssender/internal/models" |
|
|
|
|
|
|
|
|
|
@ -22,9 +23,20 @@ func NewConfig(configPath string) (*models.Config, error) {
@@ -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 |
|
|
|
|
} |
|
|
|
|
|