-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.go
41 lines (38 loc) · 1.04 KB
/
plugin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package meilisearch
import (
"github.com/allentom/harukap"
"github.com/meilisearch/meilisearch-go"
)
type Plugin struct {
Client *meilisearch.Client
OnComplete func()
}
func (p *Plugin) OnInit(e *harukap.HarukaAppEngine) error {
initLogger := e.LoggerPlugin.Logger.NewScope("MeiliSearchPlugin")
initLogger.Info("init MeiliSearch plugin")
configure := e.ConfigProvider.Manager
enable := configure.GetBool("meilisearch.enable")
if !enable {
initLogger.Info("meilisearch is disabled")
return nil
}
host := configure.GetString("meilisearch.host")
apiKey := configure.GetString("meilisearch.apiKey")
initLogger.WithFields(map[string]interface{}{
"host": host,
}).Info("init meilisearch client")
p.Client = meilisearch.NewClient(meilisearch.ClientConfig{
Host: host,
APIKey: apiKey,
})
initLogger.Info("test meilisearch connection")
status, err := p.Client.Health()
if err != nil {
return err
}
initLogger.Info("meilisearch connection success ", "status = ", status.Status)
if p.OnComplete != nil {
p.OnComplete()
}
return err
}