diff --git a/internal/utils/reflection.go b/internal/utils/reflection.go deleted file mode 100644 index 6dcd45a..0000000 --- a/internal/utils/reflection.go +++ /dev/null @@ -1,23 +0,0 @@ -package utils - -import ( - "fmt" - "reflect" -) - -// CheckMissingFields checks for missing, required fields in structs -func CheckMissingFields(obj interface{}, requiredFields []string) error { - v := reflect.ValueOf(obj).Elem() - for _, field := range requiredFields { - f := v.FieldByName(field) - if !f.IsValid() { - return fmt.Errorf("field %s is not valid", field) - } - zero := reflect.Zero(f.Type()).Interface() - current := f.Interface() - if reflect.DeepEqual(current, zero) { - return fmt.Errorf("missing required field: %s", field) - } - } - return nil -} diff --git a/pinecone/client.go b/pinecone/client.go index d53a0c3..fa42172 100644 --- a/pinecone/client.go +++ b/pinecone/client.go @@ -14,8 +14,6 @@ import ( "os" "strings" - "github.com/pinecone-io/go-pinecone/internal/utils" - "github.com/pinecone-io/go-pinecone/internal/gen" "github.com/pinecone-io/go-pinecone/internal/gen/control" "github.com/pinecone-io/go-pinecone/internal/provider" @@ -186,7 +184,7 @@ func NewClient(in NewClientParams) (*Client, error) { // Notes: // - It is important to handle the error returned by this function to ensure that the // control plane client has been created successfully before attempting to make API calls. -// - A Pinecone API key is not requried when using NewClientBase. +// - A Pinecone API key is not required when using NewClientBase. // // Returns a pointer to an initialized Client instance or an error. // @@ -510,9 +508,8 @@ func (req CreatePodIndexRequest) TotalCount() int { // fmt.Printf("Successfully created pod index: %s", idx.Name) // } func (c *Client) CreatePodIndex(ctx context.Context, in *CreatePodIndexRequest) (*Index, error) { - requiredFields := []string{"Name", "Dimension", "Metric", "Environment", "PodType"} - if err := utils.CheckMissingFields(in, requiredFields); err != nil { - return nil, fmt.Errorf("name, dimension, metric, environment, and podtype must be included in CreatePodIndexRequest: %w", err) + if in.Name == "" || in.Dimension == 0 || in.Metric == "" || in.Environment == "" || in.PodType == "" { + return nil, fmt.Errorf("name, dimension, metric, environment, and podtype must be included in CreatePodIndexRequest") } deletionProtection := pointerOrNil(control.DeletionProtection(in.DeletionProtection)) @@ -657,9 +654,8 @@ type CreateServerlessIndexRequest struct { // fmt.Printf("Successfully created serverless index: %s", idx.Name) // } func (c *Client) CreateServerlessIndex(ctx context.Context, in *CreateServerlessIndexRequest) (*Index, error) { - requiredFields := []string{"Name", "Dimension", "Metric", "Cloud", "Region"} - if err := utils.CheckMissingFields(in, requiredFields); err != nil { - return nil, fmt.Errorf("name, dimension, metric, cloud, and region must be included in CreateServerlessIndexRequest: %w", err) + if in.Name == "" || in.Dimension == 0 || in.Metric == "" || in.Cloud == "" || in.Region == "" { + return nil, fmt.Errorf("name, dimension, metric, cloud, and region must be included in CreateServerlessIndexRequest") } deletionProtection := pointerOrNil(control.DeletionProtection(in.DeletionProtection)) @@ -786,7 +782,7 @@ func (c *Client) DeleteIndex(ctx context.Context, idxName string) error { // ConfigureIndexParams contains parameters for configuring an index. For both pod-based // and serverless indexes you can configure the DeletionProtection status for an index. // For pod-based indexes you can also configure the number of Replicas and the PodType. -// Each of the fields are optional, but at least one field must be set. +// Each of the fields is optional, but at least one field must be set. // See [scale a pods-based index] for more information. // // Fields: @@ -1115,9 +1111,8 @@ type CreateCollectionRequest struct { // // [Collection]: https://docs.pinecone.io/guides/indexes/understanding-collections func (c *Client) CreateCollection(ctx context.Context, in *CreateCollectionRequest) (*Collection, error) { - requiredFields := []string{"Name", "Source"} - if err := utils.CheckMissingFields(in, requiredFields); err != nil { - return nil, fmt.Errorf("name and source must be included in CreateCollectionRequest: %w", err) + if in.Source == "" || in.Name == "" { + return nil, fmt.Errorf("name and source must be included in CreateCollectionRequest") } req := control.CreateCollectionRequest{ @@ -1348,7 +1343,7 @@ func formatError(errMap errorResponseMap) error { } func buildClientBaseOptions(in NewClientBaseParams) []control.ClientOption { - clientOptions := []control.ClientOption{} + var clientOptions []control.ClientOption // build and apply user agent header userAgentProvider := provider.NewHeaderProvider("User-Agent", useragent.BuildUserAgent(in.SourceTag)) diff --git a/pinecone/client_test.go b/pinecone/client_test.go index 4ebb39e..c8cdf12 100644 --- a/pinecone/client_test.go +++ b/pinecone/client_test.go @@ -1321,11 +1321,6 @@ func TestBuildClientBaseOptionsUnit(t *testing.T) { } // Helper functions: -func isValidUUID(u string) bool { - _, err := uuid.Parse(u) - return err == nil -} - func mockResponse(body string, statusCode int) *http.Response { return &http.Response{ Status: http.StatusText(statusCode), diff --git a/pinecone/index_connection.go b/pinecone/index_connection.go index 5e41944..ebd1e81 100644 --- a/pinecone/index_connection.go +++ b/pinecone/index_connection.go @@ -6,8 +6,6 @@ import ( "fmt" "log" - "github.com/pinecone-io/go-pinecone/internal/utils" - "github.com/pinecone-io/go-pinecone/internal/gen/data" "github.com/pinecone-io/go-pinecone/internal/useragent" "google.golang.org/grpc" @@ -843,8 +841,7 @@ type UpdateVectorRequest struct { // log.Fatalf("Failed to update vector with ID %s. Error: %s", id, err) // } func (idx *IndexConnection) UpdateVector(ctx context.Context, in *UpdateVectorRequest) error { - requiredFields := []string{"Id"} - if err := utils.CheckMissingFields(in, requiredFields); err != nil { + if in.Id == "" { return fmt.Errorf("a vector ID plus at least one of Values, SparseValues, or Metadata must be provided to update a vector") } @@ -1102,7 +1099,7 @@ func sparseValToGrpc(sv *SparseValues) *data.SparseValues { } func (idx *IndexConnection) akCtx(ctx context.Context) context.Context { - newMetadata := []string{} + var newMetadata []string for key, value := range idx.additionalMetadata { newMetadata = append(newMetadata, key, value)