Add meilisearch for user and event
Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
13
data/drivers/meilisearch.go
Normal file
13
data/drivers/meilisearch.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package drivers
|
||||
|
||||
import "github.com/meilisearch/meilisearch-go"
|
||||
|
||||
func MeiliSearch(dsn MeiliDSN) meilisearch.ServiceManager {
|
||||
return meilisearch.New(dsn.Host,
|
||||
meilisearch.WithAPIKey(dsn.ApiKey),
|
||||
meilisearch.WithContentEncoding(
|
||||
meilisearch.GzipEncoding,
|
||||
meilisearch.BestCompression,
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -16,9 +16,9 @@ func SplitHostPort(url string) (host, port string) {
|
||||
return split[0], split[1]
|
||||
}
|
||||
|
||||
func Postgres(dsn ExternalDSN) (*DBClient, error) {
|
||||
func Postgres(dsn ExternalDSN) (*gorm.DB, error) {
|
||||
host, port := SplitHostPort(dsn.Host)
|
||||
conn := "host=" + host + " user=" + dsn.Username + " password=" + dsn.Password + " dbname=" + dsn.Name + " port=" + port + " sslmode=disable TimeZone=" + config.TZ()
|
||||
db, err := gorm.Open(postgres.Open(conn), &gorm.Config{})
|
||||
return &DBClient{db}, err
|
||||
return db, err
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
package drivers
|
||||
|
||||
import (
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ExternalDSN struct {
|
||||
Host string
|
||||
Name string
|
||||
@@ -19,6 +15,7 @@ type RedisDSN struct {
|
||||
DB int
|
||||
}
|
||||
|
||||
type DBClient struct {
|
||||
*gorm.DB
|
||||
type MeiliDSN struct {
|
||||
Host string
|
||||
ApiKey string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user