mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
Initial work on async functions
This commit is contained in:
29
api/mqs/new.go
Normal file
29
api/mqs/new.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package mqs
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/iron-io/functions/api/models"
|
||||
)
|
||||
|
||||
// New will parse the URL and return the correct MQ implementation.
|
||||
func New(mqURL string) (models.MessageQueue, error) {
|
||||
// Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW
|
||||
u, err := url.Parse(mqURL)
|
||||
if err != nil {
|
||||
logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL")
|
||||
}
|
||||
logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Info("selecting MQ")
|
||||
switch u.Scheme {
|
||||
case "memory":
|
||||
return NewMemoryMQ(), nil
|
||||
case "redis":
|
||||
return NewRedisMQ(u)
|
||||
case "bolt":
|
||||
return NewBoltMQ(u)
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("mq type not supported %v", u.Scheme)
|
||||
}
|
||||
Reference in New Issue
Block a user