35 lines
666 B
Go
35 lines
666 B
Go
package models
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
|
|
"github.com/milvus-io/milvus-sdk-go/v2/client"
|
|
)
|
|
|
|
type MilvusConnection struct {
|
|
Client client.Client
|
|
}
|
|
|
|
func (m *MilvusConnection) GetClient() client.Client {
|
|
return m.Client
|
|
}
|
|
|
|
func (m *MilvusConnection) Init() (err error) {
|
|
log.Println("Milvus connection init")
|
|
os.Setenv("NO_PROXY", config.GetString("milvus.host"))
|
|
m.Client, err = client.NewGrpcClient(context.Background(), fmt.Sprintf(
|
|
"%s:%d",
|
|
config.GetString("milvus.host"),
|
|
config.GetInt("milvus.port"),
|
|
))
|
|
if err != nil {
|
|
log.Println("Milvus connection failed:", err)
|
|
return
|
|
}
|
|
log.Println("Milvus connection success")
|
|
return
|
|
}
|