mtsatellite/common/clientfactory.go

36 lines
736 B
Go
Raw Permalink Normal View History

2022-02-27 21:17:43 +01:00
// Copyright 2022 by Sascha L. Teichmann
// Use of this source code is governed by the MIT license
// that can be found in the LICENSE file.
package common
import (
"strings"
)
type DBClient interface {
QueryCuboid(cuboid Cuboid, fn func(*Block) *Block) (count int, err error)
Close() error
}
type DBClientFactory interface {
Create() (DBClient, error)
Close() error
}
2022-02-27 21:17:43 +01:00
func IsPostgreSQL(host string) (string, bool) {
if strings.HasPrefix(host, "postgres:") {
return host[len("postgres:"):], true
}
return "", false
}
func CreateDBClientFactory(host string, port int) (DBClientFactory, error) {
2022-02-27 21:17:43 +01:00
if connS, ok := IsPostgreSQL(host); ok {
return NewPGClientFactory(connS)
2022-02-27 21:17:43 +01:00
}
return NewRedisClientFactory(host, port)
2022-02-27 21:17:43 +01:00
}