meilisearch/meilisearch.go

37 lines
607 B
Go
Raw Permalink Normal View History

2022-10-27 03:03:35 +00:00
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)
}