Files
projectreshoot/internal/config/config.go

57 lines
1.0 KiB
Go

package config
import (
"git.haelnorr.com/h/golib/hws"
"git.haelnorr.com/h/golib/hwsauth"
"github.com/joho/godotenv"
"github.com/pkg/errors"
)
type Config struct {
DB *DBConfig
HWS *hws.Config
HWSAuth *hwsauth.Config
TMDB *TMDBConfig
HLOG *HLOGConfig
}
// Load the application configuration and get a pointer to the Config object
func GetConfig(envfile string) (*Config, error) {
godotenv.Load(envfile)
db, err := setupDB()
if err != nil {
return nil, errors.Wrap(err, "setupDB")
}
hws, err := hws.ConfigFromEnv()
if err != nil {
return nil, errors.Wrap(err, "hws.ConfigFromEnv")
}
hwsAuth, err := hwsauth.ConfigFromEnv()
if err != nil {
return nil, errors.Wrap(err, "hwsauth.ConfigFromEnv")
}
tmdb, err := setupTMDB()
if err != nil {
return nil, errors.Wrap(err, "setupTMDB")
}
hlog, err := setupHLOG()
if err != nil {
return nil, errors.Wrap(err, "setupHLOG")
}
config := &Config{
DB: db,
HWS: hws,
HWSAuth: hwsAuth,
TMDB: tmdb,
HLOG: hlog,
}
return config, nil
}