You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
488 B
30 lines
488 B
package config |
|
|
|
import ( |
|
"os" |
|
"ssender/internal/models" |
|
|
|
"gopkg.in/yaml.v2" |
|
) |
|
|
|
func NewConfig(configPath string) (*models.Config, error) { |
|
// Create config structure |
|
config := &models.Config{} |
|
|
|
// Open config file |
|
file, err := os.Open(configPath) |
|
if err != nil { |
|
return nil, err |
|
} |
|
defer file.Close() |
|
|
|
// Init new YAML decode |
|
d := yaml.NewDecoder(file) |
|
|
|
// Start YAML decoding from file |
|
if err := d.Decode(&config); err != nil { |
|
return nil, err |
|
} |
|
|
|
return config, nil |
|
}
|
|
|