filebrowser/backend/settings/config.go

54 lines
1.1 KiB
Go
Raw Normal View History

2023-09-01 14:00:02 +00:00
package settings
import (
"io/ioutil"
"log"
"os"
"github.com/goccy/go-yaml"
)
var GlobalConfiguration Settings
2023-09-01 22:53:22 +00:00
func init() {
2023-09-01 14:00:02 +00:00
// Open and read the YAML file
yamlFile, err := os.Open("filebrowser.yml")
if err != nil {
log.Fatalf("Error opening YAML file: %v", err)
}
defer yamlFile.Close()
yamlData, err := ioutil.ReadAll(yamlFile)
if err != nil {
log.Fatalf("Error reading YAML data: %v", err)
}
setDefaults()
// Unmarshal the YAML data into the Settings struct
err = yaml.Unmarshal(yamlData, &GlobalConfiguration)
if err != nil {
log.Fatalf("Error unmarshaling YAML data: %v", err)
}
2023-09-01 23:30:51 +00:00
log.Printf("GlobalConfiguration: \n%#v\n", GlobalConfiguration)
2023-09-01 22:35:54 +00:00
2023-09-01 14:00:02 +00:00
// Now you have the Settings struct with values from the YAML file
// You can access the values like: defaultSettings.Key, defaultSettings.Server.Port, etc.
}
func setDefaults() {
GlobalConfiguration = Settings{
Signup: true,
2023-09-01 22:35:54 +00:00
Server: Server{
IndexingInterval: 5,
Port: 8080,
2023-09-01 14:00:02 +00:00
NumImageProcessors: 1,
2023-09-01 22:35:54 +00:00
BaseURL: "/",
},
2023-09-01 14:00:02 +00:00
Auth: Auth{
2023-09-01 22:35:54 +00:00
Method: "noauth",
2023-09-01 14:00:02 +00:00
Recaptcha: Recaptcha{
Host: "",
},
},
2023-09-01 22:35:54 +00:00
}
}