leech/config/config.go

42 lines
824 B
Go

package config
import (
"encoding/json"
"log"
"os"
"path/filepath"
)
type ConfigS struct {
Host string `json:"host"`
ThumbnailJobLimit int `json:"thumbnailjoblimit"`
ServeDirs map[string]string `json:"servedirs"`
}
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)
err = decoder.Decode(&Config)
if err != nil {
panic(err)
}
}
}