filebrowser/backend/settings/config.go

57 lines
1.2 KiB
Go
Raw Normal View History

2023-09-01 14:00:02 +00:00
package settings
import (
"log"
"os"
"github.com/goccy/go-yaml"
)
var GlobalConfiguration Settings
2023-09-02 00:51:13 +00:00
func init() {
2023-09-01 14:00:02 +00:00
// Open and read the YAML file
2023-09-02 18:02:50 +00:00
yamlFile, err := os.Open("filebrowser.yaml")
2023-09-01 14:00:02 +00:00
if err != nil {
log.Fatalf("Error opening YAML file: %v", err)
}
defer yamlFile.Close()
2023-09-02 02:03:45 +00:00
stat, err := yamlFile.Stat()
if err != nil {
log.Fatalf("Error getting file information: %v", err)
}
yamlData := make([]byte, stat.Size())
_, err = yamlFile.Read(yamlData)
2023-09-01 14:00:02 +00:00
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)
}
// 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-02 00:51:13 +00:00
Server: Server{
IndexingInterval: 5,
Port: 8080,
2023-09-01 14:00:02 +00:00
NumImageProcessors: 1,
2023-09-02 02:03:45 +00:00
BaseURL: "",
2023-09-02 00:51:13 +00:00
},
2023-09-01 14:00:02 +00:00
Auth: Auth{
2023-09-02 00:51:13 +00:00
Method: "password",
2023-09-01 14:00:02 +00:00
Recaptcha: Recaptcha{
Host: "",
},
},
2023-09-02 00:51:13 +00:00
}
}