45 lines
635 B
Go
45 lines
635 B
Go
package config
|
|
|
|
import (
|
|
"encoding/json"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
DB DatabaseConfig
|
|
Matrix MatrixConfig
|
|
Server ServerConfig
|
|
}
|
|
|
|
type DatabaseConfig struct {
|
|
Filename string
|
|
}
|
|
|
|
type MatrixConfig struct {
|
|
AllowedRooms []string
|
|
DisplayName string
|
|
LogLevel uint
|
|
HomeserverURL string
|
|
UserIdentifier string
|
|
Password string
|
|
PickleKey string
|
|
}
|
|
|
|
type ServerConfig struct {
|
|
ListenAddress string
|
|
}
|
|
|
|
func ParseFromFile(path string) (config *Config, err error) {
|
|
data, err := os.ReadFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
err = json.Unmarshal(data, config)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return config, nil
|
|
}
|