package conf

import (
	"os"

	"github.com/spf13/viper"
)

func Init(file string) {
	viper.AddConfigPath(".")
	viper.AddConfigPath("..")
	viper.SetConfigFile(file)
	err := viper.ReadInConfig()
	if err != nil {
		panic(err)
	}

	// read test.key file
	var keyFile *os.File
	keyFile, err = os.Open(viper.GetString("certs.testKeyPath"))
	if err != nil {
		panic(err)
	}
	defer keyFile.Close()

	var fileInfo os.FileInfo
	fileInfo, err = keyFile.Stat()
	if err != nil {
		panic(err)
	}
	keyData := make([]byte, fileInfo.Size())
	_, err = keyFile.Read(keyData)
	if err != nil {
		panic(err)
	}

	viper.Set("test.key", string(keyData))
	
}