matrix-pretix/internal/config/config.go

50 lines
894 B
Go
Raw Permalink Normal View History

package config
import (
"encoding/json"
"os"
)
type Config struct {
2022-07-24 02:40:44 +02:00
DB DatabaseConfig
Matrix MatrixConfig
2022-07-24 02:40:44 +02:00
Server ServerConfig
}
type DatabaseConfig struct {
Filename string
}
type MatrixConfig struct {
AllowedRooms []string `json:"allowed_rooms"`
DeviceName string `json:"device_name"`
Greeting string
LogLevel uint `json:"log_level"`
HomeserverURL string `json:"homeserver_url"`
2022-07-24 22:00:25 +02:00
UserIdentifier string `json:"user_identifier"`
Password string
PickleKey string `json:"pickle_key"`
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"`
ListenAddress string `json:"listen_address"`
}
2022-07-24 04:42:44 +02:00
func ParseFromFile(path string) (*Config, error) {
data, err := os.ReadFile(path)
if err != nil {
return nil, err
}
2022-07-24 04:42:44 +02:00
config := &Config{}
err = json.Unmarshal(data, config)
if err != nil {
return nil, err
}
return config, nil
}