Move PostgreswithDHT to cmd

This commit is contained in:
Hilmar Gústafsson 2020-04-13 10:27:20 +02:00
parent b817830bfd
commit 71337ff839
3 changed files with 18 additions and 18 deletions

View file

@ -3,7 +3,9 @@ package storage
import ( import (
"net/url" "net/url"
dht "github.com/libp2p/go-libp2p-kad-dht"
pubsub "github.com/libp2p/go-libp2p-pubsub" pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/matrix-org/dendrite/cmd/dendrite-p2p-demo/storage/postgreswithdht"
"github.com/matrix-org/dendrite/cmd/dendrite-p2p-demo/storage/postgreswithpubsub" "github.com/matrix-org/dendrite/cmd/dendrite-p2p-demo/storage/postgreswithpubsub"
"github.com/matrix-org/dendrite/publicroomsapi/storage" "github.com/matrix-org/dendrite/publicroomsapi/storage"
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3" "github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
@ -12,6 +14,22 @@ import (
const schemePostgres = "postgres" const schemePostgres = "postgres"
const schemeFile = "file" const schemeFile = "file"
// NewPublicRoomsServerDatabase opens a database connection.
func NewPublicRoomsServerDatabaseWithDHT(dataSourceName string, dht *dht.IpfsDHT) (storage.Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
}
switch uri.Scheme {
case schemePostgres:
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
case schemeFile:
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
default:
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
}
}
// NewPublicRoomsServerDatabase opens a database connection. // NewPublicRoomsServerDatabase opens a database connection.
func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub) (storage.Database, error) { func NewPublicRoomsServerDatabaseWithPubSub(dataSourceName string, pubsub *pubsub.PubSub) (storage.Database, error) {
uri, err := url.Parse(dataSourceName) uri, err := url.Parse(dataSourceName)

View file

@ -19,9 +19,7 @@ package storage
import ( import (
"net/url" "net/url"
dht "github.com/libp2p/go-libp2p-kad-dht"
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgres" "github.com/matrix-org/dendrite/publicroomsapi/storage/postgres"
"github.com/matrix-org/dendrite/publicroomsapi/storage/postgreswithdht"
"github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3" "github.com/matrix-org/dendrite/publicroomsapi/storage/sqlite3"
) )
@ -43,19 +41,3 @@ func NewPublicRoomsServerDatabase(dataSourceName string) (Database, error) {
return postgres.NewPublicRoomsServerDatabase(dataSourceName) return postgres.NewPublicRoomsServerDatabase(dataSourceName)
} }
} }
// NewPublicRoomsServerDatabase opens a database connection.
func NewPublicRoomsServerDatabaseWithDHT(dataSourceName string, dht *dht.IpfsDHT) (Database, error) {
uri, err := url.Parse(dataSourceName)
if err != nil {
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
}
switch uri.Scheme {
case schemePostgres:
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
case schemeFile:
return sqlite3.NewPublicRoomsServerDatabase(dataSourceName)
default:
return postgreswithdht.NewPublicRoomsServerDatabase(dataSourceName, dht)
}
}