Files
fn-serverless/api/datastore/datastore.go
Travis Reeder d5116397b6 API extension points (#473)
* API endpoint extensions working.

extensions example.

* Added server.NewEnv and some docs for the API extensions example.

extensions example.
example main.go.

* Uncommented special handler stuff.

* Added section in docs for extending API linking to example main.go.

* Commented out special_handler test

* Changed to NewFromEnv
2017-01-30 12:14:28 -08:00

28 lines
669 B
Go

package datastore
import (
"fmt"
"net/url"
"github.com/Sirupsen/logrus"
"github.com/iron-io/functions/api/datastore/bolt"
"github.com/iron-io/functions/api/datastore/postgres"
"github.com/iron-io/functions/api/models"
)
func New(dbURL string) (models.Datastore, error) {
u, err := url.Parse(dbURL)
if err != nil {
logrus.WithError(err).WithFields(logrus.Fields{"url": dbURL}).Fatal("bad DB URL")
}
logrus.WithFields(logrus.Fields{"db": u.Scheme}).Debug("creating new datastore")
switch u.Scheme {
case "bolt":
return bolt.New(u)
case "postgres":
return postgres.New(u)
default:
return nil, fmt.Errorf("db type not supported %v", u.Scheme)
}
}