Start of the config

This commit is contained in:
Gary Kramlich
2021-11-18 02:03:42 -06:00
parent 3305345ce8
commit 5b3811ce96
5 changed files with 63 additions and 1 deletions

10
config/appservice.go Normal file
View File

@@ -0,0 +1,10 @@
package config
type appservice struct {
Address string `yaml:"address"`
Hostname string `yaml:"hostname"`
Port uint16 `yaml:"port"`
ASToken string `yaml:"as_token"`
HSToken string `yaml:"hs_token"`
}

35
config/config.go Normal file
View File

@@ -0,0 +1,35 @@
package config
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
type Config struct {
Homeserver homeserver `yaml:"homeserver"`
Appservice appservice `yaml:"appservice"`
}
func FromBytes(data []byte) (*Config, error) {
cfg := Config{}
if err := yaml.Unmarshal(data, &cfg); err != nil {
return nil, err
}
return &cfg, nil
}
func FromString(str string) (*Config, error) {
return FromBytes([]byte(str))
}
func FromFile(filename string) (*Config, error) {
data, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
return FromBytes(data)
}

7
config/homeserver.go Normal file
View File

@@ -0,0 +1,7 @@
package config
type homeserver struct {
Address string `yaml:"address"`
Domain string `yaml:"domain"`
StatusEndpoint string `yaml:"status_endpoint"`
}