Start of the config
This commit is contained in:
10
config/appservice.go
Normal file
10
config/appservice.go
Normal 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
35
config/config.go
Normal 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
7
config/homeserver.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package config
|
||||
|
||||
type homeserver struct {
|
||||
Address string `yaml:"address"`
|
||||
Domain string `yaml:"domain"`
|
||||
StatusEndpoint string `yaml:"status_endpoint"`
|
||||
}
|
||||
Reference in New Issue
Block a user