Files
accounting/internal/config/config.go

44 lines
861 B
Go

package config
import (
"encoding/json"
"os"
"git.schreifuchs.ch/lou-taylor/accounting/internal/email"
)
// PDF holds the configuration for the PDF generator.
type PDF struct {
Hostname string `json:"hostname"`
}
// Gitea holds the configuration for the Gitea client.
type Gitea struct {
URL string `json:"url"`
Token string `json:"token"`
}
// Config holds the configuration for the entire application.
type Config struct {
Email email.Config `json:"email"`
PDF PDF `json:"pdf"`
Gitea Gitea `json:"gitea"`
}
// Load loads the configuration from a JSON file.
func Load(path string) (*Config, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
cfg := &Config{}
decoder := json.NewDecoder(file)
if err := decoder.Decode(cfg); err != nil {
return nil, err
}
return cfg, nil
}