32 lines
562 B
Go
32 lines
562 B
Go
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
|
|
}
|