mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
25 lines
570 B
Go
25 lines
570 B
Go
package logs
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/fnproject/fn/api/datastore/sql"
|
|
"github.com/fnproject/fn/api/models"
|
|
)
|
|
|
|
func New(dbURL string) (models.FnLog, 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 log store")
|
|
switch u.Scheme {
|
|
case "sqlite3", "postgres", "mysql":
|
|
return sql.New(u)
|
|
default:
|
|
return nil, fmt.Errorf("db type not supported %v", u.Scheme)
|
|
}
|
|
}
|