Skip to content
app_config.go 626 B
Newer Older
Lo^2's avatar
Lo^2 committed
package importer
Lo^2's avatar
wip
Lo^2 committed

import (
Lo^2's avatar
Lo^2 committed
	"code.electrolab.fr/it/vote.electrolab.fr/service/email"
Lo^2's avatar
wip
Lo^2 committed
	"encoding/json"
	"fmt"
	"os"
)

Lo^2's avatar
Lo^2 committed
type AppConfig struct {
Lo^2's avatar
wip
Lo^2 committed
	Database struct {
		Connection string
	}
Lo^2's avatar
Lo^2 committed
	Email email.SmtpConfig
Lo^2's avatar
wip
Lo^2 committed
}

Lo^2's avatar
Lo^2 committed
func ReadConfigFile(path string) (*AppConfig, error) {
Lo^2's avatar
wip
Lo^2 committed
	f, err := os.Open(path)
	if err != nil {
		return nil, fmt.Errorf("Error while opening %s: %s", path, err.Error())
	}
	defer f.Close()

	configDecoder := json.NewDecoder(f)

Lo^2's avatar
Lo^2 committed
	config := new(AppConfig)
Lo^2's avatar
wip
Lo^2 committed
	err = configDecoder.Decode(config)
	if err != nil {
		return nil, fmt.Errorf("Error parsing config file %s: %s", path, err.Error())
	}

	return config, nil
}