Remove accounts from config file; add log level

This commit is contained in:
Alex 2020-02-27 10:44:28 +01:00
parent 7fa2842f5d
commit be9278ab02

42
main.go
View file

@ -5,12 +5,8 @@ import (
"encoding/hex"
"encoding/json"
"flag"
"fmt"
_ "fmt"
"io/ioutil"
"os"
_ "strings"
_ "time"
log "github.com/sirupsen/logrus"
"gopkg.in/yaml.v2"
@ -18,20 +14,15 @@ import (
"git.deuxfleurs.fr/Deuxfleurs/easybridge/mxlib"
)
type ConfigAccount struct {
Protocol string `json:"protocol"`
Config map[string]string `json:"config"`
}
type ConfigFile struct {
ASBindAddr string `json:"appservice_bind_addr"`
WebBindAddr string `json:"web_bind_addr"`
Registration string `json:"registration"`
Server string `json:"homeserver_url"`
DbType string `json:"db_type"`
DbPath string `json:"db_path"`
MatrixDomain string `json:"matrix_domain"`
Accounts map[string]map[string]ConfigAccount `json:"accounts"`
LogLevel string `json:"log_level"`
ASBindAddr string `json:"appservice_bind_addr"`
WebBindAddr string `json:"web_bind_addr"`
Registration string `json:"registration"`
Server string `json:"homeserver_url"`
DbType string `json:"db_type"`
DbPath string `json:"db_path"`
MatrixDomain string `json:"matrix_domain"`
}
var configFlag = flag.String("config", "./config.json", "Configuration file path")
@ -41,13 +32,13 @@ var registration *mxlib.Registration
func readConfig() ConfigFile {
config_file := ConfigFile{
LogLevel: "info",
ASBindAddr: "0.0.0.0:8321",
WebBindAddr: "0.0.0.0:8281",
Registration: "./registration.yaml",
Server: "http://localhost:8008",
DbType: "sqlite3",
DbPath: "easybridge.db",
Accounts: map[string]map[string]ConfigAccount{},
}
_, err := os.Stat(*configFlag)
@ -152,13 +143,17 @@ func readRegistration(file string) mxlib.Registration {
}
func main() {
log.SetLevel(log.DebugLevel)
flag.Parse()
config_file := readConfig()
config = &config_file
log_level, err := log.ParseLevel(config.LogLevel)
if err != nil {
log.Fatal(err)
}
log.SetLevel(log_level)
reg_file := readRegistration(config.Registration)
registration = &reg_file
@ -169,13 +164,6 @@ func main() {
StartWeb()
for user, accounts := range config.Accounts {
mxid := fmt.Sprintf("@%s:%s", user, config.MatrixDomain)
for name, params := range accounts {
SetAccount(mxid, name, params.Protocol, params.Config)
}
}
err = <-errch
if err != nil {
log.Fatal(err)