add scraping the torrent topics rss files
This commit is contained in:
34
internal/config/config.go
Normal file
34
internal/config/config.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
func New() {
|
||||
configFilePath := viper.GetString("config-file")
|
||||
configDir := "./" + filepath.Dir(configFilePath)
|
||||
|
||||
viper.SetConfigName(filepath.Base(configFilePath))
|
||||
viper.AddConfigPath(configDir)
|
||||
|
||||
err := viper.ReadInConfig() // Find and read the config file
|
||||
if err != nil { // Handle errors reading the config file
|
||||
panic(fmt.Errorf("fatal error config file: %w", err))
|
||||
}
|
||||
|
||||
viper.SetDefault("ConfigDir", configDir)
|
||||
scope := viper.GetString("scope")
|
||||
if scope != "" {
|
||||
viper.SetConfigName(scope)
|
||||
viper.AddConfigPath(configDir)
|
||||
err := viper.MergeInConfig()
|
||||
if err != nil {
|
||||
log.Fatalf("fatal error config file: %v", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user