feat: add configuration management and update deployment files
This commit is contained in:
39
cmn/conf/conf.go
Normal file
39
cmn/conf/conf.go
Normal file
@@ -0,0 +1,39 @@
|
||||
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))
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user