unified-push-xmpp/gateway/main.go

61 lines
1.4 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"
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"`
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)
}
2021-09-12 12:14:09 +02:00
// just for more beautiful config file - jere
config.XMPP.EndpointURL = config.EndpointURL
2021-09-14 01:32:37 +02:00
config.XMPP.JWTSecret = config.JWTSecret
2021-09-12 12:14:09 +02:00
go func() {
if err := config.XMPP.Run(); err != nil {
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
}