github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/api/mqs/new.go (about)

     1  package mqs
     2  
     3  import (
     4  	"fmt"
     5  	"net/url"
     6  	"strings"
     7  
     8  	"github.com/Sirupsen/logrus"
     9  	"github.com/iron-io/functions/api/models"
    10  )
    11  
    12  // New will parse the URL and return the correct MQ implementation.
    13  func New(mqURL string) (models.MessageQueue, error) {
    14  	// Play with URL schemes here: https://play.golang.org/p/xWAf9SpCBW
    15  	u, err := url.Parse(mqURL)
    16  	if err != nil {
    17  		logrus.WithError(err).WithFields(logrus.Fields{"url": mqURL}).Fatal("bad MQ URL")
    18  	}
    19  	logrus.WithFields(logrus.Fields{"mq": u.Scheme}).Debug("selecting MQ")
    20  	switch u.Scheme {
    21  	case "memory":
    22  		return NewMemoryMQ(), nil
    23  	case "redis":
    24  		return NewRedisMQ(u)
    25  	case "bolt":
    26  		return NewBoltMQ(u)
    27  	}
    28  	if strings.HasPrefix(u.Scheme, "ironmq") {
    29  		return NewIronMQ(u), nil
    30  	}
    31  
    32  	return nil, fmt.Errorf("mq type not supported %v", u.Scheme)
    33  }