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

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)
}