unified-push-xmpp/distributor/main.go

49 lines
1.0 KiB
Go
Raw Normal View History

2021-09-05 13:31:06 +02:00
package main
import (
2021-09-05 19:20:27 +02:00
"os"
"os/signal"
"syscall"
"errors"
2021-09-05 19:20:27 +02:00
"github.com/bdlm/log"
"unifiedpush.org/go/np2p_dbus/distributor"
2021-09-05 13:31:06 +02:00
)
var dbus *distributor.DBus
2021-09-05 19:20:27 +02:00
func main() {
dbus = distributor.NewDBus("org.unifiedpush.Distributor.xmpp")
dbus.StartHandling(handler{})
2021-09-05 19:20:27 +02:00
log.Info("startup")
// Wait for INT/TERM
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
sig := <-sigs
log.Infof("received %s", sig)
2021-09-05 13:31:06 +02:00
}
type handler struct {
}
func (h handler) Register(appName, token string) (string,string,error) {
log.WithFields(map[string]interface{}{
"name": appName,
"token": token,
}).Info("distributor-register")
endpoint := "https://up.chat.sum7.eu/UP?appid="+appName+"&token="+token
if endpoint != "" {
return endpoint, "", nil
}
return "", "reason to app", errors.New("Unknown error")
}
func (h handler) Unregister(token string) {
log.WithFields(map[string]interface{}{
"token": token,
}).Info("distributor-unregister")
appID := ""
_ = dbus.NewConnector(appID).Unregistered(token)
}