共用配置文件导入

This commit is contained in:
2023-12-03 04:43:53 +08:00
parent 6590fcbb11
commit c7b892e2c0
10 changed files with 70 additions and 158 deletions

View File

@@ -18,12 +18,11 @@ func (m *MilvusConnection) GetClient() client.Client {
func (m *MilvusConnection) Init() (err error) {
log.Println("Milvus connection init")
host := Viper.Get("milvus.host").(string)
port := Viper.Get("milvus.port").(int)
m.Client, err = client.NewGrpcClient(
context.Background(),
fmt.Sprintf("%s:%d", host, port),
)
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
@@ -31,16 +30,3 @@ func (m *MilvusConnection) Init() (err error) {
log.Println("Milvus connection success")
return
}
func (m *MilvusConnection) GetCollection(collection_name string) (collection *client.Client, err error) {
if m.Client == nil {
m.Init()
}
err = m.Client.LoadCollection(context.Background(), collection_name, false)
if err != nil {
log.Println("Milvus load collection failed:", err)
return
}
collection = &m.Client
return
}