meilisearch/meilisearch.go

37 lines
607 B
Go

package meilisearch
import (
"fmt"
ms "github.com/meilisearch/meilisearch-go"
)
var client *ms.Client
func Connect(cfg Config) error {
// validate config
if err := cfg.Validate(); err != nil {
return err
}
// connect
client = ms.NewClient(ms.ClientConfig{
Host: cfg.URL,
APIKey: cfg.APIKey,
})
// check connection
if !client.IsHealthy() {
return fmt.Errorf("cannot connect to %s", cfg.URL)
}
fmt.Printf("⚡️[meilisearch]: connected to %s \n", cfg.URL)
return nil
}
// getIndex return meilisearch index
func getIndex(index string) *ms.Index {
return client.Index(index)
}