unified-push-xmpp/gateway/main.go

68 lines
1.6 KiB
Go
Raw Normal View History

2021-09-05 13:31:06 +02:00
package main
import (
2021-09-09 23:12:29 +02:00
"flag"
"dev.sum7.eu/genofire/golang-lib/file"
2021-09-12 12:14:09 +02:00
"dev.sum7.eu/genofire/golang-lib/web"
apiStatus "dev.sum7.eu/genofire/golang-lib/web/api/status"
webM "dev.sum7.eu/genofire/golang-lib/web/metrics"
2021-09-09 23:12:29 +02:00
"github.com/bdlm/log"
"github.com/bdlm/std/logger"
2021-09-05 13:31:06 +02:00
)
2021-09-12 12:14:09 +02:00
var VERSION = "development"
type configData struct {
2021-09-14 01:32:37 +02:00
JWTSecret JWTSecret `toml"jwt_secret"`
EndpointURL string `toml:"endpoint_url"`
XMPP XMPPService `toml:"xmpp"`
Webserver web.Service `toml:"webserver"`
Log struct {
Level uint32 `toml:"level"`
Timestamp bool `toml:"timestamp"`
} `toml:"log"`
2021-09-12 12:14:09 +02:00
}
2021-09-05 13:31:06 +02:00
func main() {
2021-09-12 12:14:09 +02:00
webM.VERSION = VERSION
apiStatus.VERSION = VERSION
webM.NAMESPACE = "unifiedpush"
2021-09-09 23:12:29 +02:00
configPath := "config.toml"
2021-09-12 12:14:09 +02:00
showVersion := false
2021-09-09 23:12:29 +02:00
flag.StringVar(&configPath, "c", configPath, "path to configuration file")
2021-09-12 12:14:09 +02:00
flag.BoolVar(&showVersion, "version", showVersion, "show current version")
2021-09-09 23:12:29 +02:00
flag.Parse()
2021-09-12 12:14:09 +02:00
if showVersion {
log.WithField("version", VERSION).Info("Version")
return
}
config := &configData{}
2021-09-09 23:12:29 +02:00
if err := file.ReadTOML(configPath, config); err != nil {
log.Panicf("open config file: %s", err)
}
log.SetLevel(logger.Level(config.Log.Level))
log.SetFormatter(&log.TextFormatter{
DisableTimestamp: !config.Log.Timestamp,
})
2021-09-12 12:14:09 +02:00
go func() {
if err := config.XMPP.Run(config.JWTSecret, config.EndpointURL); err != nil {
2021-09-12 12:14:09 +02:00
log.Panicf("startup xmpp: %v", err)
}
}()
2021-09-14 01:32:37 +02:00
config.Webserver.ModuleRegister(Bind(&config.XMPP, config.JWTSecret))
2021-09-09 23:12:29 +02:00
log.Info("startup")
2021-09-12 12:14:09 +02:00
if err := config.Webserver.Run(); err != nil {
log.Fatal(err)
2021-09-09 23:12:29 +02:00
}
2021-09-05 13:31:06 +02:00
}