26 lines
444 B
Go
Executable File
26 lines
444 B
Go
Executable File
package config
|
|
|
|
import (
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Config struct {
|
|
DatabaseURL string
|
|
Port string
|
|
}
|
|
|
|
func LoadConfig(path string) (*Config, error) {
|
|
viper.AddConfigPath(path)
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("yaml")
|
|
|
|
if err := viper.ReadInConfig(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Config{
|
|
DatabaseURL: viper.GetString("database.url"),
|
|
Port: viper.GetString("server.port"),
|
|
}, nil
|
|
}
|