33 lines
842 B
Go
33 lines
842 B
Go
package config
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func InitConfig(cfgFile string) func() {
|
|
return func () {
|
|
if cfgFile != "" {
|
|
// Use config file from the flag.
|
|
viper.SetConfigFile(cfgFile)
|
|
} else {
|
|
// Search config in home directory with name ".mcd" (without extension).
|
|
viper.AddConfigPath(".")
|
|
viper.SetConfigType("toml")
|
|
viper.SetConfigName("mcd")
|
|
}
|
|
viper.SetEnvPrefix("MCD")
|
|
|
|
viper.AutomaticEnv() // read in environment variables that match
|
|
|
|
// If a config file is found, read it in.
|
|
if err := viper.ReadInConfig(); err == nil {
|
|
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
|
}
|
|
viper.SetDefault("java.path", "/usr/bin/java")
|
|
viper.SetDefault("java.args", []string{"-Xms2G", "-Xmx3G"})
|
|
viper.SetDefault("server.jar", "./server.jar")
|
|
}
|
|
}
|