Use env vars
This commit is contained in:
parent
9b56b3a5f6
commit
38e0d61a5b
@ -20,7 +20,7 @@ var (
|
||||
|
||||
func init() {
|
||||
refreshCmd.Flags().IntVar(&interval, "interval", 15, "How long in minutes to wait before refreshing feeds")
|
||||
viper.BindPFlag("refreshTimeoutMinutes", refreshCmd.Flags().Lookup("interval"))
|
||||
viper.BindPFlag("REFRESH_TIMEOUT", refreshCmd.Flags().Lookup("interval"))
|
||||
|
||||
rootCmd.AddCommand(refreshCmd)
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ var fp = gofeed.NewParser()
|
||||
var feedStore = &FeedStore{}
|
||||
|
||||
func Refresh() error {
|
||||
interval := viper.GetInt("refreshTimeoutMinutes")
|
||||
interval := viper.GetInt("REFRESH_TIMEOUT")
|
||||
|
||||
for {
|
||||
fmt.Println("Refreshing feeds...")
|
||||
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
func (fs *FeedStore) getDB() *gorm.DB {
|
||||
if fs.db == nil {
|
||||
db, err := gorm.Open(sqlite.Open(viper.GetString("dbPath")), &gorm.Config{
|
||||
db, err := gorm.Open(sqlite.Open(viper.GetString("DB_PATH")), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Error),
|
||||
})
|
||||
if err != nil {
|
||||
|
18
main.go
18
main.go
@ -10,24 +10,12 @@ import (
|
||||
func main() {
|
||||
// Load config
|
||||
setDefaultConfig()
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("$HOME/.gopherss")
|
||||
viper.AddConfigPath(".")
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||
// Ignore
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
viper.WatchConfig()
|
||||
}
|
||||
viper.AutomaticEnv()
|
||||
|
||||
cmd.Execute()
|
||||
}
|
||||
|
||||
func setDefaultConfig() {
|
||||
viper.SetDefault("refreshTimeoutMinutes", 15)
|
||||
viper.SetDefault("dbPath", "./feeds.db")
|
||||
viper.SetDefault("REFRESH_TIMEOUT", 15)
|
||||
viper.SetDefault("DB_PATH", "./feeds.db")
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user