2022-07-23 00:33:05 +02:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
2022-08-10 22:42:23 +02:00
|
|
|
|
|
|
|
"git.luj0ga.de/franconian/matrix"
|
2022-07-23 00:33:05 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2022-07-24 02:40:44 +02:00
|
|
|
DB DatabaseConfig
|
2022-08-10 22:42:23 +02:00
|
|
|
Matrix matrix.Config
|
2022-07-24 02:40:44 +02:00
|
|
|
Server ServerConfig
|
|
|
|
}
|
|
|
|
|
|
|
|
type DatabaseConfig struct {
|
|
|
|
Filename string
|
2022-07-23 00:33:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 02:40:44 +02:00
|
|
|
type ServerConfig struct {
|
2022-07-24 21:41:01 +02:00
|
|
|
APIToken string `json:"api_token"`
|
|
|
|
BaseURL string `json:"base_url"`
|
2022-07-24 04:24:11 +02:00
|
|
|
ListenAddress string `json:"listen_address"`
|
2022-07-23 00:33:05 +02:00
|
|
|
}
|
|
|
|
|
2022-07-24 04:42:44 +02:00
|
|
|
func ParseFromFile(path string) (*Config, error) {
|
2022-07-23 00:33:05 +02:00
|
|
|
data, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2022-07-24 04:42:44 +02:00
|
|
|
config := &Config{}
|
|
|
|
|
2022-07-23 00:33:05 +02:00
|
|
|
err = json.Unmarshal(data, config)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return config, nil
|
|
|
|
}
|