Add active publish logic to streams

This commit is contained in:
Alex X
2023-09-17 20:29:28 +03:00
parent dca8279e0c
commit 209fe09806
3 changed files with 45 additions and 0 deletions
+22
View File
@@ -73,3 +73,25 @@ func Location(url string) (string, error) {
return "", nil
}
// TODO: rework
type ConsumerHandler func(url string) (core.Consumer, func(), error)
var consumerHandlers = map[string]ConsumerHandler{}
func HandleConsumerFunc(scheme string, handler ConsumerHandler) {
consumerHandlers[scheme] = handler
}
func GetConsumer(url string) (core.Consumer, func(), error) {
if i := strings.IndexByte(url, ':'); i > 0 {
scheme := url[:i]
if handler, ok := consumerHandlers[scheme]; ok {
return handler(url)
}
}
return nil, nil, errors.New("streams: unsupported scheme: " + url)
}