photoprism/internal/event/hub.go
Michael Mayer dac272468e Sharing: Render preview image & site info
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2019-12-11 14:10:20 +01:00

55 lines
903 B
Go

package event
import (
"github.com/leandro-lugaresi/hub"
)
type Hub = hub.Hub
type Data = hub.Fields
type Message = hub.Message
var channelCap = 10
var sharedHub = NewHub()
func NewHub() *Hub {
return hub.New()
}
func SharedHub() *Hub {
return sharedHub
}
func Error(msg string) {
Log.Error(msg)
Publish("notify.error", Data{"msg": msg})
}
func Success(msg string) {
Log.Info(msg)
Publish("notify.success", Data{"msg": msg})
}
func Info(msg string) {
Log.Info(msg)
Publish("notify.info", Data{"msg": msg})
}
func Warning(msg string) {
Log.Warn(msg)
Publish("notify.warning", Data{"msg": msg})
}
func Publish(event string, data Data) {
SharedHub().Publish(Message{
Name: event,
Fields: data,
})
}
func Subscribe(topics ...string) hub.Subscription {
return SharedHub().Subscribe(channelCap, topics...)
}
func Unsubscribe(s hub.Subscription) {
SharedHub().Unsubscribe(s)
}