38 lines
702 B
Go
38 lines
702 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
)
|
|
|
|
type ConfigS struct {
|
|
Host string `json:"host"`
|
|
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)
|
|
decoder.Decode(&Config)
|
|
}
|
|
}
|