35 lines
792 B
Go
35 lines
792 B
Go
package drivers
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"github.com/meilisearch/meilisearch-go"
|
|
"github.com/spf13/viper"
|
|
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp"
|
|
)
|
|
|
|
func MeiliSearch(dsn MeiliDSN) meilisearch.ServiceManager {
|
|
serviceName := viper.GetString("search.service_name")
|
|
|
|
otelTransport := otelhttp.NewTransport(
|
|
http.DefaultTransport,
|
|
otelhttp.WithSpanNameFormatter(func(operation string, r *http.Request) string {
|
|
return fmt.Sprintf("%s %s", serviceName, r.Method)
|
|
}),
|
|
)
|
|
|
|
httpClient := &http.Client{
|
|
Transport: otelTransport,
|
|
}
|
|
|
|
return meilisearch.New(dsn.Host,
|
|
meilisearch.WithAPIKey(dsn.ApiKey),
|
|
meilisearch.WithCustomClient(httpClient),
|
|
meilisearch.WithContentEncoding(
|
|
meilisearch.GzipEncoding,
|
|
meilisearch.BestCompression,
|
|
),
|
|
)
|
|
}
|