41 lines
610 B
Go
41 lines
610 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
|
|
"git.luj0ga.de/franconian/matrix"
|
|
)
|
|
|
|
type Config struct {
|
|
DB DatabaseConfig
|
|
Matrix matrix.Config
|
|
Server ServerConfig
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Filename string
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
APIToken string `json:"api_token"`
|
|
BaseURL string `json:"base_url"`
|
|
ListenAddress string `json:"listen_address"`
|
|
}
|
|
|
|
func ParseFromFile(path string) (*Config, error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
config := &Config{}
|
|
|
|
err = json.Unmarshal(data, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|