2019-03-23 14:56:59 +00:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
const Stash = "stash"
|
|
|
|
const Cache = "cache"
|
|
|
|
const Generated = "generated"
|
|
|
|
const Metadata = "metadata"
|
|
|
|
const Downloads = "downloads"
|
|
|
|
|
|
|
|
const Database = "database"
|
|
|
|
|
2019-04-11 17:55:58 +00:00
|
|
|
const Host = "host"
|
|
|
|
const Port = "port"
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
func Set(key string, value interface{}) {
|
|
|
|
viper.Set(key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Write() error {
|
|
|
|
return viper.WriteConfig()
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetStashPaths() []string {
|
|
|
|
return viper.GetStringSlice(Stash)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCachePath() string {
|
|
|
|
return viper.GetString(Cache)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetGeneratedPath() string {
|
|
|
|
return viper.GetString(Generated)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetMetadataPath() string {
|
|
|
|
return viper.GetString(Metadata)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetDatabasePath() string {
|
|
|
|
return viper.GetString(Database)
|
|
|
|
}
|
|
|
|
|
2019-04-11 17:55:58 +00:00
|
|
|
func GetHost() string {
|
|
|
|
return viper.GetString(Host)
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetPort() int {
|
|
|
|
return viper.GetInt(Port)
|
|
|
|
}
|
|
|
|
|
2019-03-23 14:56:59 +00:00
|
|
|
func IsValid() bool {
|
|
|
|
setPaths := viper.IsSet(Stash) && viper.IsSet(Cache) && viper.IsSet(Generated) && viper.IsSet(Metadata)
|
|
|
|
// TODO: check valid paths
|
|
|
|
return setPaths
|
|
|
|
}
|