Skip to content

Commit

Permalink
Refine code style, examples & documents (#562)
Browse files Browse the repository at this point in the history
Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Aug 23, 2023
1 parent 1c766f8 commit f8f1c3f
Show file tree
Hide file tree
Showing 40 changed files with 1,078 additions and 1,173 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Go SDK for [Milvus](https://github.com/milvus-io/milvus). To contribute code to

|Milvus version| Recommended Go SDK version |
|:-----:|:-----:|
| 2.2.x | [2.2.2](https://github.com/milvus-io/milvus-sdk-go/tree/v2.2.2) |
| 2.3.x | [2.3.0](https://github.com/milvus-io/milvus-sdk-go/tree/v2.3.0) |
| 2.2.x | [2.2.7](https://github.com/milvus-io/milvus-sdk-go/tree/v2.2.7) |
| 2.1.0 | [2.1.0](https://github.com/milvus-io/milvus-sdk-go/tree/v2.1.0) |
| 2.0.0 | [2.0.0](https://github.com/milvus-io/milvus-sdk-go/tree/v2.0.0) |
| 1.1.x | [1.1.0](https://github.com/milvus-io/milvus-sdk-go/tree/v1.1.0) |
Expand All @@ -27,7 +28,7 @@ Note: Major versions is NOT compatible between Milvus and SDK

### Prerequisites

Go 1.15 or higher
Go 1.17 or higher

### Install Milvus Go SDK

Expand Down
6 changes: 3 additions & 3 deletions client/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ package client
import (
"context"

server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
)

// GetVersion returns milvus server version information.
// GetVersion returns milvus milvuspb.version information.
func (c *GrpcClient) GetVersion(ctx context.Context) (string, error) {
if c.Service == nil {
return "", ErrClientNotReady
}
resp, err := c.Service.GetVersion(ctx, &server.GetVersionRequest{})
resp, err := c.Service.GetVersion(ctx, &milvuspb.GetVersionRequest{})
if err != nil {
return "", err
}
Expand Down
8 changes: 4 additions & 4 deletions client/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package client
import (
"context"

server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
)

// CreateAlias creates an alias for collection
Expand All @@ -28,7 +28,7 @@ func (c *GrpcClient) CreateAlias(ctx context.Context, collName string, alias str
return ErrClientNotReady
}

req := &server.CreateAliasRequest{
req := &milvuspb.CreateAliasRequest{
DbName: "", // reserved
CollectionName: collName,
Alias: alias,
Expand All @@ -51,7 +51,7 @@ func (c *GrpcClient) DropAlias(ctx context.Context, alias string) error {
return ErrClientNotReady
}

req := &server.DropAliasRequest{
req := &milvuspb.DropAliasRequest{
DbName: "", // reserved
Alias: alias,
}
Expand All @@ -73,7 +73,7 @@ func (c *GrpcClient) AlterAlias(ctx context.Context, collName string, alias stri
return ErrClientNotReady
}

req := &server.AlterAliasRequest{
req := &milvuspb.AlterAliasRequest{
DbName: "", // reserved
CollectionName: collName,
Alias: alias,
Expand Down
32 changes: 16 additions & 16 deletions client/alias_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"testing"

"github.com/golang/protobuf/proto"
common "github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/stretchr/testify/assert"
)

Expand All @@ -34,14 +34,14 @@ func TestGrpcCreateAlias(t *testing.T) {
t.Run("normal create alias", func(t *testing.T) {

mockServer.SetInjection(MCreateAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.CreateAliasRequest)
req, ok := raw.(*milvuspb.CreateAliasRequest)
if !ok {
t.FailNow()
}
assert.Equal(t, "testcoll", req.CollectionName)
assert.Equal(t, "collAlias", req.Alias)

return &common.Status{ErrorCode: common.ErrorCode_Success}, nil
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil
})
defer mockServer.DelInjection(MCreateAlias)
err := c.CreateAlias(ctx, "testcoll", "collAlias")
Expand All @@ -51,17 +51,17 @@ func TestGrpcCreateAlias(t *testing.T) {
t.Run("alias duplicated", func(t *testing.T) {
m := make(map[string]struct{})
mockServer.SetInjection(MCreateAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.CreateAliasRequest)
req, ok := raw.(*milvuspb.CreateAliasRequest)
if !ok {
t.FailNow()
}
status := common.ErrorCode_Success
status := commonpb.ErrorCode_Success
_, has := m[req.GetAlias()]
if has {
status = common.ErrorCode_UnexpectedError
status = commonpb.ErrorCode_UnexpectedError
}
m[req.GetAlias()] = struct{}{}
return &common.Status{ErrorCode: status}, nil
return &commonpb.Status{ErrorCode: status}, nil
})
defer mockServer.DelInjection(MCreateAlias)

Expand All @@ -81,13 +81,13 @@ func TestGrpcDropAlias(t *testing.T) {

t.Run("normal drop alias", func(t *testing.T) {
mockServer.SetInjection(MDropAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.DropAliasRequest)
req, ok := raw.(*milvuspb.DropAliasRequest)
if !ok {
t.FailNow()
}
assert.Equal(t, "collAlias", req.Alias)

return &common.Status{ErrorCode: common.ErrorCode_Success}, nil
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil
})
defer mockServer.DelInjection(MDropAlias)
err := c.DropAlias(ctx, "collAlias")
Expand All @@ -96,13 +96,13 @@ func TestGrpcDropAlias(t *testing.T) {

t.Run("drop alias error", func(t *testing.T) {
mockServer.SetInjection(MDropAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.DropAliasRequest)
req, ok := raw.(*milvuspb.DropAliasRequest)
if !ok {
t.FailNow()
}
assert.Equal(t, "collAlias", req.Alias)

return &common.Status{ErrorCode: common.ErrorCode_UnexpectedError}, nil
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError}, nil
})
defer mockServer.DelInjection(MDropAlias)
err := c.DropAlias(ctx, "collAlias")
Expand All @@ -120,14 +120,14 @@ func TestGrpcAlterAlias(t *testing.T) {

t.Run("normal alter alias", func(t *testing.T) {
mockServer.SetInjection(MAlterAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.AlterAliasRequest)
req, ok := raw.(*milvuspb.AlterAliasRequest)
if !ok {
t.FailNow()
}
assert.Equal(t, collName, req.CollectionName)
assert.Equal(t, aliasName, req.Alias)

return &common.Status{ErrorCode: common.ErrorCode_Success}, nil
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_Success}, nil
})
defer mockServer.DelInjection(MAlterAlias)
err := c.AlterAlias(ctx, collName, aliasName)
Expand All @@ -136,14 +136,14 @@ func TestGrpcAlterAlias(t *testing.T) {

t.Run("alter alias error", func(t *testing.T) {
mockServer.SetInjection(MAlterAlias, func(_ context.Context, raw proto.Message) (proto.Message, error) {
req, ok := raw.(*server.AlterAliasRequest)
req, ok := raw.(*milvuspb.AlterAliasRequest)
if !ok {
t.FailNow()
}
assert.Equal(t, collName, req.CollectionName)
assert.Equal(t, aliasName, req.Alias)

return &common.Status{ErrorCode: common.ErrorCode_UnexpectedError}, nil
return &commonpb.Status{ErrorCode: commonpb.ErrorCode_UnexpectedError}, nil
})
defer mockServer.DelInjection(MAlterAlias)
err := c.AlterAlias(ctx, collName, aliasName)
Expand Down
10 changes: 5 additions & 5 deletions client/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package client
import (
"context"

server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-sdk-go/v2/internal/utils/crypto"
)

Expand All @@ -12,7 +12,7 @@ func (c *GrpcClient) CreateCredential(ctx context.Context, username string, pass
if c.Service == nil {
return ErrClientNotReady
}
req := &server.CreateCredentialRequest{
req := &milvuspb.CreateCredentialRequest{
Username: username,
Password: crypto.Base64Encode(password),
}
Expand All @@ -32,7 +32,7 @@ func (c *GrpcClient) UpdateCredential(ctx context.Context, username string, oldP
if c.Service == nil {
return ErrClientNotReady
}
req := &server.UpdateCredentialRequest{
req := &milvuspb.UpdateCredentialRequest{
Username: username,
OldPassword: crypto.Base64Encode(oldPassword),
NewPassword: crypto.Base64Encode(newPassword),
Expand All @@ -53,7 +53,7 @@ func (c *GrpcClient) DeleteCredential(ctx context.Context, username string) erro
if c.Service == nil {
return ErrClientNotReady
}
req := &server.DeleteCredentialRequest{
req := &milvuspb.DeleteCredentialRequest{
Username: username,
}
resp, err := c.Service.DeleteCredential(ctx, req)
Expand All @@ -72,7 +72,7 @@ func (c *GrpcClient) ListCredUsers(ctx context.Context) ([]string, error) {
if c.Service == nil {
return nil, ErrClientNotReady
}
req := &server.ListCredUsersRequest{}
req := &milvuspb.ListCredUsersRequest{}
resp, err := c.Service.ListCredUsers(ctx, req)
if err != nil {
return nil, err
Expand Down
40 changes: 20 additions & 20 deletions client/authentication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"github.com/cockroachdb/errors"

"github.com/golang/protobuf/proto"
common "github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
server "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/milvus-io/milvus-proto/go-api/v2/commonpb"
"github.com/milvus-io/milvus-proto/go-api/v2/milvuspb"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -38,17 +38,17 @@ func TestGrpcClient_CreateCredential(t *testing.T) {

t.Run("create credential grpc error", func(t *testing.T) {
mockServer.SetInjection(MCreateCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{}, errors.New("mockServer.d grpc error")
return &commonpb.Status{}, errors.New("mockServer.d grpc error")
})
defer mockServer.DelInjection(MCreateCredential)
err := c.CreateCredential(ctx, testUsername, testPassword)
assert.Error(t, err)
})

t.Run("create credential server error", func(t *testing.T) {
t.Run("create credential milvuspb.error", func(t *testing.T) {
mockServer.SetInjection(MCreateCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{
ErrorCode: common.ErrorCode_UnexpectedError,
return &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: "Service is not healthy",
}, nil
})
Expand All @@ -74,17 +74,17 @@ func TestGrpcClient_UpdateCredential(t *testing.T) {

t.Run("update credential grpc error", func(t *testing.T) {
mockServer.SetInjection(MUpdateCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{}, errors.New("mockServer.d grpc error")
return &commonpb.Status{}, errors.New("mockServer.d grpc error")
})
defer mockServer.DelInjection(MUpdateCredential)
err := c.UpdateCredential(ctx, testUsername, testPassword, testPassword)
assert.Error(t, err)
})

t.Run("update credential server error", func(t *testing.T) {
t.Run("update credential milvuspb.error", func(t *testing.T) {
mockServer.SetInjection(MUpdateCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{
ErrorCode: common.ErrorCode_UnexpectedError,
return &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: "Service is not healthy",
}, nil
})
Expand All @@ -110,17 +110,17 @@ func TestGrpcClient_DeleteCredential(t *testing.T) {

t.Run("delete credential grpc error", func(t *testing.T) {
mockServer.SetInjection(MDeleteCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{}, errors.New("mockServer.d grpc error")
return &commonpb.Status{}, errors.New("mockServer.d grpc error")
})
defer mockServer.DelInjection(MDeleteCredential)
err := c.DeleteCredential(ctx, testUsername)
assert.Error(t, err)
})

t.Run("delete credential server error", func(t *testing.T) {
t.Run("delete credential milvuspb.error", func(t *testing.T) {
mockServer.SetInjection(MDeleteCredential, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &common.Status{
ErrorCode: common.ErrorCode_UnexpectedError,
return &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: "Service is not healthy",
}, nil
})
Expand All @@ -136,7 +136,7 @@ func TestGrpcClient_ListCredUsers(t *testing.T) {

t.Run("list credential users normal", func(t *testing.T) {
mockServer.SetInjection(MListCredUsers, func(ctx context.Context, _ proto.Message) (proto.Message, error) {
resp := &server.ListCredUsersResponse{
resp := &milvuspb.ListCredUsersResponse{
Usernames: []string{testUsername},
}
s, err := SuccessStatus()
Expand All @@ -151,18 +151,18 @@ func TestGrpcClient_ListCredUsers(t *testing.T) {

t.Run("list credential users grpc error", func(t *testing.T) {
mockServer.SetInjection(MListCredUsers, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &server.ListCredUsersResponse{}, errors.New("mockServer.d grpc error")
return &milvuspb.ListCredUsersResponse{}, errors.New("mockServer.d grpc error")
})
defer mockServer.DelInjection(MListCredUsers)
_, err := c.ListCredUsers(ctx)
assert.Error(t, err)
})

t.Run("list credential users server error", func(t *testing.T) {
t.Run("list credential users milvuspb.error", func(t *testing.T) {
mockServer.SetInjection(MListCredUsers, func(ctx context.Context, raw proto.Message) (proto.Message, error) {
return &server.ListCredUsersResponse{
Status: &common.Status{
ErrorCode: common.ErrorCode_UnexpectedError,
return &milvuspb.ListCredUsersResponse{
Status: &commonpb.Status{
ErrorCode: commonpb.ErrorCode_UnexpectedError,
Reason: "Service is not healthy",
},
}, nil
Expand Down
4 changes: 0 additions & 4 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ import (
"github.com/milvus-io/milvus-sdk-go/v2/entity"
)

const (
sdkVerion = `v2.3.0-pre+dev`
)

// Client is the interface used to communicate with Milvus
type Client interface {
// -- client --
Expand Down
Loading

0 comments on commit f8f1c3f

Please sign in to comment.