leech/config/config.go

42 lines
824 B
Go
Raw Normal View History

2024-04-27 12:16:43 +02:00
package config
2024-04-27 12:40:07 +02:00
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
2024-04-27 12:16:43 +02:00
2024-04-27 12:40:07 +02:00
type ConfigS struct {
Host string `json:"host"`
ThumbnailJobLimit int `json:"thumbnailjoblimit"`
ServeDirs map[string]string `json:"servedirs"`
2024-04-27 12:40:07 +02:00
}
var Config ConfigS
func Init() {
chosenConfigPath := "/etc/leech/"
// Deal with a JSON configuration file in that folder.
configFile := filepath.Join(chosenConfigPath, "config.json")
// Does the file not exist?
if _, err := os.Stat(configFile); os.IsNotExist(err) {
log.Fatal("config file couldn't be found")
} else {
// Load the existing file.
fh, err := os.Open(configFile)
if err != nil {
panic(err)
}
defer fh.Close()
decoder := json.NewDecoder(fh)
2024-06-10 19:50:11 +02:00
err = decoder.Decode(&Config)
if err != nil {
panic(err)
}
2024-04-27 12:40:07 +02:00
}
2024-04-27 12:16:43 +02:00
}