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.
32 lines
598 B
32 lines
598 B
package database
|
|
|
|
import (
|
|
"fmt"
|
|
"gopkg.in/yaml.v3"
|
|
"os"
|
|
)
|
|
|
|
type DatabaseConfig struct {
|
|
Driver string `yaml:"driver"`
|
|
DataSourceName string `yaml:"dataSourceName"`
|
|
}
|
|
|
|
type Config struct {
|
|
Database DatabaseConfig `yaml:"database"`
|
|
}
|
|
|
|
func LoadConfig(filePath string) (*Config, error) {
|
|
yamlFile, err := os.ReadFile(filePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to read config file: %v", err)
|
|
}
|
|
|
|
var config Config
|
|
err = yaml.Unmarshal(yamlFile, &config)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to unmarshal config file: %v", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|