matrix-pretix/internal/config/config.go

45 lines
635 B
Go
Raw 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 {
2022-07-24 02:40:44 +02:00
AllowedRooms []string
DisplayName string
LogLevel uint
HomeserverURL string
UserIdentifier string
Password string
2022-07-24 02:40:44 +02:00
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
}