Add meilisearch for user and event

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2025-12-26 02:16:23 +08:00
parent 3dbcc00a2d
commit 6681ffccdf
19 changed files with 229 additions and 15 deletions

View 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,
),
)
}

View File

@@ -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
}

View File

@@ -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
}