goatcounter-systemd/config/config.go

33 lines
562 B
Go
Raw Permalink Normal View History

2024-09-28 16:20:24 -04:00
package config
import (
"encoding/json"
"fmt"
"os"
)
type Site struct {
URL string
APIKey string
Hosts []string
}
type Config struct {
LogIdentifier string
Sites []Site
}
func FromFilePath(filePath string) (config Config, err error) {
data, err := os.ReadFile(filePath)
if err != nil {
return config, fmt.Errorf("failed to read config file path %s: %w", filePath, err)
}
err = json.Unmarshal(data, &config)
if err != nil {
return config, fmt.Errorf("failed to unmarshal JSON from file path %s: %w", filePath, err)
}
return config, nil
}