diff --git a/pkg/common/adapters/database/bun.go b/pkg/common/adapters/database/bun.go index 236d60b..fea9848 100644 --- a/pkg/common/adapters/database/bun.go +++ b/pkg/common/adapters/database/bun.go @@ -39,7 +39,7 @@ func (h *QueryDebugHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) // This helps identify which specific field is causing scanning issues func debugScanIntoStruct(rows interface{}, dest interface{}) error { v := reflect.ValueOf(dest) - if v.Kind() != reflect.Ptr { + if v.Kind() != reflect.Pointer { return fmt.Errorf("dest must be a pointer") } @@ -59,7 +59,7 @@ func debugScanIntoStruct(rows interface{}, dest interface{}) error { logger.Debug(" Slice element type: %s", elemType) // If slice of pointers, get the underlying type - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { structType = elemType.Elem() } else { structType = elemType @@ -747,7 +747,7 @@ func checkIfRelationAlreadyLoaded(parents reflect.Value, relationName string) (r // Get the first parent to check the relation field firstParent := parents.Index(0) - if firstParent.Kind() == reflect.Ptr { + if firstParent.Kind() == reflect.Pointer { firstParent = firstParent.Elem() } @@ -762,7 +762,7 @@ func checkIfRelationAlreadyLoaded(parents reflect.Value, relationName string) (r // Check if any parent has a non-empty slice for i := 0; i < parents.Len(); i++ { parent := parents.Index(i) - if parent.Kind() == reflect.Ptr { + if parent.Kind() == reflect.Pointer { parent = parent.Elem() } field := parent.FieldByName(relationName) @@ -771,7 +771,7 @@ func checkIfRelationAlreadyLoaded(parents reflect.Value, relationName string) (r allRelated := reflect.MakeSlice(field.Type(), 0, field.Len()*parents.Len()) for j := 0; j < parents.Len(); j++ { p := parents.Index(j) - if p.Kind() == reflect.Ptr { + if p.Kind() == reflect.Pointer { p = p.Elem() } f := p.FieldByName(relationName) @@ -784,7 +784,7 @@ func checkIfRelationAlreadyLoaded(parents reflect.Value, relationName string) (r return allRelated, true } } - } else if relationField.Kind() == reflect.Ptr { + } else if relationField.Kind() == reflect.Pointer { // Check if it's a pointer (has-one/belongs-to) if !relationField.IsNil() { // Already loaded! Collect all related records from all parents @@ -792,7 +792,7 @@ func checkIfRelationAlreadyLoaded(parents reflect.Value, relationName string) (r allRelated := reflect.MakeSlice(reflect.SliceOf(relatedType), 0, parents.Len()) for j := 0; j < parents.Len(); j++ { p := parents.Index(j) - if p.Kind() == reflect.Ptr { + if p.Kind() == reflect.Pointer { p = p.Elem() } f := p.FieldByName(relationName) @@ -816,7 +816,7 @@ func (b *BunSelectQuery) loadCustomPreloads(ctx context.Context) error { // Get the actual data from the model modelValue := reflect.ValueOf(model.Value()) - if modelValue.Kind() == reflect.Ptr { + if modelValue.Kind() == reflect.Pointer { modelValue = modelValue.Elem() } @@ -884,7 +884,7 @@ func (b *BunSelectQuery) loadRelationLevel(ctx context.Context, parentRecords re // Get the first record to inspect the struct type firstRecord := parentRecords.Index(0) - if firstRecord.Kind() == reflect.Ptr { + if firstRecord.Kind() == reflect.Pointer { firstRecord = firstRecord.Elem() } @@ -930,7 +930,7 @@ func (b *BunSelectQuery) loadRelationLevel(ctx context.Context, parentRecords re if isSlice { relatedType = relatedType.Elem() } - if relatedType.Kind() == reflect.Ptr { + if relatedType.Kind() == reflect.Pointer { relatedType = relatedType.Elem() } @@ -1018,7 +1018,7 @@ func extractForeignKeyValues(records reflect.Value, fkFieldName string) ([]inter for i := 0; i < records.Len(); i++ { record := records.Index(i) - if record.Kind() == reflect.Ptr { + if record.Kind() == reflect.Pointer { record = record.Elem() } @@ -1083,7 +1083,7 @@ func associateRelatedRecords(parents, related reflect.Value, fieldName string, r for i := 0; i < related.Len(); i++ { relRecord := related.Index(i) relRecordElem := relRecord - if relRecordElem.Kind() == reflect.Ptr { + if relRecordElem.Kind() == reflect.Pointer { relRecordElem = relRecordElem.Elem() } @@ -1109,7 +1109,7 @@ func associateRelatedRecords(parents, related reflect.Value, fieldName string, r for i := 0; i < parents.Len(); i++ { parentPtr := parents.Index(i) parent := parentPtr - if parent.Kind() == reflect.Ptr { + if parent.Kind() == reflect.Pointer { parent = parent.Elem() } @@ -1332,11 +1332,11 @@ func (b *BunSelectQuery) ScanModel(ctx context.Context) (err error) { modelInfo = fmt.Sprintf("Model type: %T", modelValue) v := reflect.ValueOf(modelValue) - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { v = v.Elem() } if v.Kind() == reflect.Slice { - if v.Type().Elem().Kind() == reflect.Ptr { + if v.Type().Elem().Kind() == reflect.Pointer { modelInfo += fmt.Sprintf(", Slice of: %s", v.Type().Elem().Elem().Name()) } else { modelInfo += fmt.Sprintf(", Slice of: %s", v.Type().Elem().Name()) diff --git a/pkg/common/adapters/database/gorm.go b/pkg/common/adapters/database/gorm.go index 49f9dec..5e3f034 100644 --- a/pkg/common/adapters/database/gorm.go +++ b/pkg/common/adapters/database/gorm.go @@ -800,7 +800,7 @@ func (g *GormInsertQuery) Scan(ctx context.Context, dest interface{}) (err error col := g.returningColumns[0] if g.model != nil { val := reflect.ValueOf(g.model) - if val.Kind() == reflect.Ptr { + if val.Kind() == reflect.Pointer { val = val.Elem() } if val.Kind() == reflect.Struct { diff --git a/pkg/common/adapters/database/pgsql.go b/pkg/common/adapters/database/pgsql.go index 5ac862a..d98bd30 100644 --- a/pkg/common/adapters/database/pgsql.go +++ b/pkg/common/adapters/database/pgsql.go @@ -1195,7 +1195,7 @@ func (p *PgSQLSelectQuery) applySubqueryPreloads(ctx context.Context, dest inter // Use reflection to process the destination destValue := reflect.ValueOf(dest) - if destValue.Kind() != reflect.Ptr { + if destValue.Kind() != reflect.Pointer { return fmt.Errorf("dest must be a pointer") } @@ -1222,7 +1222,7 @@ func (p *PgSQLSelectQuery) applySubqueryPreloads(ctx context.Context, dest inter // loadPreloadsForRecord loads all preload relationships for a single record func (p *PgSQLSelectQuery) loadPreloadsForRecord(ctx context.Context, record reflect.Value, preloads []preloadConfig) error { - if record.Kind() == reflect.Ptr { + if record.Kind() == reflect.Pointer { if record.IsNil() { return nil } @@ -1299,7 +1299,7 @@ func (p *PgSQLSelectQuery) executePreloadQuery(ctx context.Context, field reflec } else { // Single struct - create a pointer if needed var target reflect.Value - if field.Kind() == reflect.Ptr { + if field.Kind() == reflect.Pointer { target = reflect.New(field.Type().Elem()) } else { target = reflect.New(field.Type()) @@ -1312,7 +1312,7 @@ func (p *PgSQLSelectQuery) executePreloadQuery(ctx context.Context, field reflec } // Set the field - if field.Kind() == reflect.Ptr { + if field.Kind() == reflect.Pointer { field.Set(target) } else { field.Set(target.Elem()) @@ -1329,7 +1329,7 @@ func (p *PgSQLSelectQuery) getRelationMetadata(fieldName string) *relationMetada } modelType := reflect.TypeOf(p.model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } @@ -1378,7 +1378,7 @@ func (p *PgSQLSelectQuery) getRelationMetadataFromField(modelType reflect.Type, if fieldType.Kind() == reflect.Slice { fieldType = fieldType.Elem() } - if fieldType.Kind() == reflect.Ptr { + if fieldType.Kind() == reflect.Pointer { fieldType = fieldType.Elem() } @@ -1411,7 +1411,7 @@ func scanRows(rows *sql.Rows, dest interface{}) error { // Get destination type destValue := reflect.ValueOf(dest) - if destValue.Kind() != reflect.Ptr { + if destValue.Kind() != reflect.Pointer { return fmt.Errorf("dest must be a pointer") } @@ -1466,7 +1466,7 @@ func scanRowsToMapSlice(rows *sql.Rows, columns []string, destValue reflect.Valu // scanRowsToStructSlice scans rows into a slice of structs func scanRowsToStructSlice(rows *sql.Rows, columns []string, destValue reflect.Value) error { elemType := destValue.Type().Elem() - isPtr := elemType.Kind() == reflect.Ptr + isPtr := elemType.Kind() == reflect.Pointer if isPtr { elemType = elemType.Elem() diff --git a/pkg/common/adapters/database/query_metrics.go b/pkg/common/adapters/database/query_metrics.go index f457213..80ee6ce 100644 --- a/pkg/common/adapters/database/query_metrics.go +++ b/pkg/common/adapters/database/query_metrics.go @@ -71,7 +71,7 @@ func entityNameFromModel(model interface{}, table string) string { } modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -108,7 +108,7 @@ func tableNameProviderFromModel(model interface{}) (common.TableNameProvider, bo } modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } diff --git a/pkg/common/handler_utils.go b/pkg/common/handler_utils.go index b687dec..209871f 100644 --- a/pkg/common/handler_utils.go +++ b/pkg/common/handler_utils.go @@ -25,7 +25,7 @@ func ValidateAndUnwrapModel(model interface{}) (*ValidateAndUnwrapModelResult, e originalType := modelType // Unwrap pointers, slices, and arrays to get to the base struct type - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -126,15 +126,15 @@ func GetRelationshipInfo(modelType reflect.Type, relationName string) *Relations // Get related model type if field.Type.Kind() == reflect.Slice { elemType := field.Type.Elem() - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { info.RelatedModel = reflect.New(elemType).Elem().Interface() } - } else if field.Type.Kind() == reflect.Ptr || field.Type.Kind() == reflect.Struct { + } else if field.Type.Kind() == reflect.Pointer || field.Type.Kind() == reflect.Struct { elemType := field.Type - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { @@ -155,16 +155,16 @@ func GetRelationshipInfo(modelType reflect.Type, relationName string) *Relations info.RelationType = "hasMany" // Get the element type for slice elemType := field.Type.Elem() - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { info.RelatedModel = reflect.New(elemType).Elem().Interface() } - } else if field.Type.Kind() == reflect.Ptr || field.Type.Kind() == reflect.Struct { + } else if field.Type.Kind() == reflect.Pointer || field.Type.Kind() == reflect.Struct { info.RelationType = "belongsTo" elemType := field.Type - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { @@ -177,7 +177,7 @@ func GetRelationshipInfo(modelType reflect.Type, relationName string) *Relations // Get the element type for many2many (always slice) if field.Type.Kind() == reflect.Slice { elemType := field.Type.Elem() - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { @@ -239,7 +239,7 @@ func GetTableNameFromModel(model interface{}) string { modelType := reflect.TypeOf(model) // Unwrap pointers - for modelType != nil && modelType.Kind() == reflect.Ptr { + for modelType != nil && modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } diff --git a/pkg/common/recursive_crud.go b/pkg/common/recursive_crud.go index 04b1290..a6e4fcd 100644 --- a/pkg/common/recursive_crud.go +++ b/pkg/common/recursive_crud.go @@ -69,7 +69,7 @@ func (p *NestedCUDProcessor) ProcessNestedCUD( // Get model type for reflection modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -224,7 +224,7 @@ func (p *NestedCUDProcessor) filterValidFields(data map[string]interface{}, mode } modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -410,7 +410,7 @@ func (p *NestedCUDProcessor) processChildRelations( if relatedModelType.Kind() == reflect.Slice { relatedModelType = relatedModelType.Elem() } - if relatedModelType.Kind() == reflect.Ptr { + if relatedModelType.Kind() == reflect.Pointer { relatedModelType = relatedModelType.Elem() } @@ -590,7 +590,7 @@ func shouldUseNestedProcessorDepth(data map[string]interface{}, model interface{ // Get model type modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } diff --git a/pkg/common/validation.go b/pkg/common/validation.go index 0264773..23b6817 100644 --- a/pkg/common/validation.go +++ b/pkg/common/validation.go @@ -31,7 +31,7 @@ func (v *ColumnValidator) buildValidColumns() { modelType := reflect.TypeOf(v.model) // Unwrap pointers, slices, and arrays to get to the base struct type - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -290,7 +290,7 @@ func (v *ColumnValidator) FilterRequestOptions(options RequestOptions) RequestOp // Filter Preload columns validPreloads := make([]PreloadOption, 0, len(options.Preload)) modelType := reflect.TypeOf(v.model) - if modelType != nil && modelType.Kind() == reflect.Ptr { + if modelType != nil && modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } for idx := range options.Preload { diff --git a/pkg/modelregistry/model_registry.go b/pkg/modelregistry/model_registry.go index d5fe1e6..632cc55 100644 --- a/pkg/modelregistry/model_registry.go +++ b/pkg/modelregistry/model_registry.go @@ -107,7 +107,7 @@ func (r *DefaultModelRegistry) RegisterModel(name string, model interface{}) err originalType := modelType // Unwrap pointers, slices, and arrays to check the underlying type - for modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array { + for modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array { modelType = modelType.Elem() } @@ -124,7 +124,7 @@ func (r *DefaultModelRegistry) RegisterModel(name string, model interface{}) err // Additional check: ensure model is not a pointer finalType := reflect.TypeOf(model) - if finalType.Kind() == reflect.Ptr { + if finalType.Kind() == reflect.Pointer { return fmt.Errorf("model must be a non-pointer struct, got pointer to %s. Use MyModel{} instead of &MyModel{}", finalType.Elem().Name()) } diff --git a/pkg/openapi/generator.go b/pkg/openapi/generator.go index 61593c3..9acc102 100644 --- a/pkg/openapi/generator.go +++ b/pkg/openapi/generator.go @@ -387,7 +387,7 @@ func (g *Generator) generateModelSchema(model interface{}) Schema { } modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } if modelType.Kind() != reflect.Struct { @@ -418,7 +418,7 @@ func (g *Generator) generateModelSchema(model interface{}) Schema { schema.Properties[fieldName] = propSchema // Check if field is required (not a pointer and no omitempty) - if field.Type.Kind() != reflect.Ptr && !strings.Contains(jsonTag, "omitempty") { + if field.Type.Kind() != reflect.Pointer && !strings.Contains(jsonTag, "omitempty") { schema.Required = append(schema.Required, fieldName) } } @@ -431,7 +431,7 @@ func (g *Generator) generatePropertySchema(field reflect.StructField) *Schema { schema := &Schema{} fieldType := field.Type - if fieldType.Kind() == reflect.Ptr { + if fieldType.Kind() == reflect.Pointer { fieldType = fieldType.Elem() } @@ -453,7 +453,7 @@ func (g *Generator) generatePropertySchema(field reflect.StructField) *Schema { case reflect.Slice, reflect.Array: schema.Type = "array" elemType := fieldType.Elem() - if elemType.Kind() == reflect.Ptr { + if elemType.Kind() == reflect.Pointer { elemType = elemType.Elem() } if elemType.Kind() == reflect.Struct { diff --git a/pkg/reflection/helpers.go b/pkg/reflection/helpers.go index 71a1850..7194fd6 100644 --- a/pkg/reflection/helpers.go +++ b/pkg/reflection/helpers.go @@ -9,7 +9,7 @@ func Len(v any) int { val := reflect.ValueOf(v) valKind := val.Kind() - if valKind == reflect.Ptr { + if valKind == reflect.Pointer { val = val.Elem() } @@ -57,7 +57,7 @@ func IsEmptyValue(v any) bool { return true } rv := reflect.ValueOf(v) - if rv.Kind() == reflect.Ptr { + if rv.Kind() == reflect.Pointer { if rv.IsNil() { return true } @@ -80,12 +80,12 @@ func IsEmptyValue(v any) bool { // If the type is a slice of pointers, it returns the element type of the pointer within the slice. // If neither condition is met, it returns the original type. func GetPointerElement(v reflect.Type) reflect.Type { - if v.Kind() == reflect.Ptr { + if v.Kind() == reflect.Pointer { return v.Elem() } - if v.Kind() == reflect.Slice && v.Elem().Kind() == reflect.Ptr { + if v.Kind() == reflect.Slice && v.Elem().Kind() == reflect.Pointer { subElem := v.Elem() - if subElem.Elem().Kind() == reflect.Ptr { + if subElem.Elem().Kind() == reflect.Pointer { return subElem.Elem().Elem() } return v.Elem() @@ -104,7 +104,7 @@ func GetJSONNameForField(modelType reflect.Type, fieldName string) string { // Unwrap pointer and slice indirections to reach the struct type for { switch modelType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: modelType = modelType.Elem() continue } diff --git a/pkg/reflection/model_utils.go b/pkg/reflection/model_utils.go index 8c753f8..966cb7b 100644 --- a/pkg/reflection/model_utils.go +++ b/pkg/reflection/model_utils.go @@ -226,7 +226,7 @@ func buildJSONToDBMap(modelType reflect.Type, result map[string]string, scanOnly // Handle embedded structs if field.Anonymous { ft := field.Type - if ft.Kind() == reflect.Ptr { + if ft.Kind() == reflect.Pointer { ft = ft.Elem() } isScanOnly := scanOnly @@ -544,7 +544,7 @@ func IsColumnWritable(model any, columnName string) bool { // Unwrap pointers and slices to get to the base struct type for modelType != nil { switch modelType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: modelType = modelType.Elem() continue } @@ -709,7 +709,7 @@ func GetColumnTypeFromModel(model interface{}, colName string) reflect.Kind { modelType := reflect.TypeOf(model) // Dereference pointer if needed - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } @@ -886,7 +886,7 @@ func GetRelationType(model interface{}, fieldName string) RelationType { // Unwrap pointer → slice → pointer chains to reach the underlying struct for { switch modelType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: modelType = modelType.Elem() continue } @@ -947,7 +947,7 @@ func GetRelationType(model interface{}, fieldName string) RelationType { // Slice indicates has-many or many-to-many return RelationHasMany } - if fieldType.Kind() == reflect.Ptr { + if fieldType.Kind() == reflect.Pointer { // Pointer to single struct usually indicates belongs-to or has-one // Check if it has foreignKey (belongs-to) or references (has-one) if strings.Contains(gormTag, "foreignKey:") { @@ -963,7 +963,7 @@ func GetRelationType(model interface{}, fieldName string) RelationType { // Slice of structs → has-many return RelationHasMany } - if fieldType.Kind() == reflect.Ptr || fieldType.Kind() == reflect.Struct { + if fieldType.Kind() == reflect.Pointer || fieldType.Kind() == reflect.Struct { // Single struct → belongs-to (default assumption for safety) // Using belongs-to as default ensures we use JOIN, which is safer return RelationBelongsTo @@ -990,7 +990,7 @@ func GetRelationType(model interface{}, fieldName string) RelationType { // Strategy 1 is skipped if the matched field is a declared relation (rel:) or // has a GORM tag but carries no explicit FK — callers should use convention. func GetForeignKeyColumn(modelType reflect.Type, parentKey string) []string { - for modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice { + for modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice { modelType = modelType.Elem() } if modelType.Kind() != reflect.Struct { @@ -1123,7 +1123,7 @@ func MapToStruct(dataMap map[string]interface{}, target interface{}) error { } targetValue := reflect.ValueOf(target) - if targetValue.Kind() != reflect.Ptr { + if targetValue.Kind() != reflect.Pointer { return fmt.Errorf("target must be a pointer to a struct") } @@ -1226,8 +1226,8 @@ func setFieldValue(field reflect.Value, value interface{}) error { } // Handle pointer fields - if field.Kind() == reflect.Ptr { - if valueReflect.Kind() != reflect.Ptr { + if field.Kind() == reflect.Pointer { + if valueReflect.Kind() != reflect.Pointer { // Create a new pointer and set its value newPtr := reflect.New(field.Type().Elem()) if err := setFieldValue(newPtr.Elem(), value); err != nil { @@ -1418,14 +1418,14 @@ func convertSlice(targetSlice reflect.Value, sourceSlice reflect.Value) error { // Handle nil elements if sourceValue == nil { // For pointer types, nil is valid - if targetElemType.Kind() == reflect.Ptr { + if targetElemType.Kind() == reflect.Pointer { targetElem.Set(reflect.Zero(targetElemType)) } continue } // If target element type is a pointer to struct, we need to create new instances - if targetElemType.Kind() == reflect.Ptr { + if targetElemType.Kind() == reflect.Pointer { // Create a new instance of the pointed-to type newElemPtr := reflect.New(targetElemType.Elem()) @@ -1588,7 +1588,7 @@ func GetValidJSONFieldNames(modelType reflect.Type) map[string]bool { // Unwrap pointers and slices to get to the base struct type for modelType != nil { switch modelType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: modelType = modelType.Elem() continue } @@ -1616,7 +1616,7 @@ func collectValidFieldNames(typ reflect.Type, validFields map[string]bool) { // Check for embedded structs if field.Anonymous { fieldType := field.Type - if fieldType.Kind() == reflect.Ptr { + if fieldType.Kind() == reflect.Pointer { fieldType = fieldType.Elem() } if fieldType.Kind() == reflect.Struct { @@ -1655,7 +1655,7 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{ for { switch modelType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: modelType = modelType.Elem() continue } @@ -1724,7 +1724,7 @@ func getRelationModelSingleLevel(model interface{}, fieldName string) interface{ for { switch targetType.Kind() { - case reflect.Ptr, reflect.Slice: + case reflect.Pointer, reflect.Slice: targetType = targetType.Elem() if targetType == nil { return nil diff --git a/pkg/resolvemcp/handler.go b/pkg/resolvemcp/handler.go index f2ccfdf..ac1f3f6 100644 --- a/pkg/resolvemcp/handler.go +++ b/pkg/resolvemcp/handler.go @@ -443,7 +443,7 @@ func (h *Handler) executeCreate(ctx context.Context, schema, entity string, data } // Re-fetch after insert to capture DB-generated defaults/triggers. modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } fetchedRecord := reflect.New(modelType).Interface() @@ -467,7 +467,7 @@ func (h *Handler) executeCreate(ctx context.Context, schema, entity string, data case []interface{}: modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } originals := make([]map[string]interface{}, 0, len(v)) @@ -567,7 +567,7 @@ func (h *Handler) executeUpdate(ctx context.Context, schema, entity, id string, err = h.db.RunInTransaction(ctx, func(tx common.Database) error { // Read existing record modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } existingRecord := reflect.New(modelType).Interface() @@ -641,7 +641,7 @@ func (h *Handler) executeUpdate(ctx context.Context, schema, entity, id string, // Re-fetch the record after transaction commits to capture DB-generated changes. modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } fetchedRecord := reflect.New(modelType).Interface() @@ -701,7 +701,7 @@ func (h *Handler) executeDelete(ctx context.Context, schema, entity, id string) } modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } diff --git a/pkg/resolvemcp/tools.go b/pkg/resolvemcp/tools.go index 7499ae5..584da31 100644 --- a/pkg/resolvemcp/tools.go +++ b/pkg/resolvemcp/tools.go @@ -67,7 +67,7 @@ func buildModelInfo(schema, entity string, model interface{}) modelInfo { // Unwrap to base struct type modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice) { modelType = modelType.Elem() } if modelType == nil || modelType.Kind() != reflect.Struct { @@ -87,7 +87,7 @@ func buildModelInfo(schema, entity string, model interface{}) modelInfo { fieldType, found := modelType.FieldByName(d.Name) if found { ft := fieldType.Type - if ft.Kind() == reflect.Ptr { + if ft.Kind() == reflect.Pointer { ft = ft.Elem() } isUserStruct := ft.Kind() == reflect.Struct && ft.Name() != "Time" && ft.PkgPath() != "" @@ -106,7 +106,7 @@ func buildModelInfo(schema, entity string, model interface{}) modelInfo { goType := d.DataType if goType == "" && found { ft := fieldType.Type - for ft.Kind() == reflect.Ptr { + for ft.Kind() == reflect.Pointer { ft = ft.Elem() } goType = ft.Name() diff --git a/pkg/resolvespec/handler.go b/pkg/resolvespec/handler.go index fd1c29b..bb35db1 100644 --- a/pkg/resolvespec/handler.go +++ b/pkg/resolvespec/handler.go @@ -243,7 +243,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st // Validate and unwrap model type to get base struct modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -1547,7 +1547,7 @@ func (h *Handler) handleDelete(ctx context.Context, w common.ResponseWriter, id // First, fetch the record that will be deleted modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } recordToDelete := reflect.New(modelType).Interface() @@ -1822,7 +1822,7 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co modelType := reflect.TypeOf(model) // Unwrap pointers, slices, and arrays to get to the base struct type - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -1966,7 +1966,7 @@ func getColumnType(field reflect.StructField) string { func isNullable(field reflect.StructField) bool { // Check if it's a pointer type - if field.Type.Kind() == reflect.Ptr { + if field.Type.Kind() == reflect.Pointer { return true } @@ -1992,7 +1992,7 @@ func (h *Handler) applyPreloads(model interface{}, query common.SelectQuery, pre modelType := reflect.TypeOf(model) // Unwrap pointers, slices, and arrays to get to the base struct type - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -2140,7 +2140,7 @@ func toSnakeCase(s string) string { func (h *Handler) setRowNumbersOnRecords(records interface{}, offset int) { // Get the reflect value of the records recordsValue := reflect.ValueOf(records) - if recordsValue.Kind() == reflect.Ptr { + if recordsValue.Kind() == reflect.Pointer { recordsValue = recordsValue.Elem() } @@ -2155,7 +2155,7 @@ func (h *Handler) setRowNumbersOnRecords(records interface{}, offset int) { record := recordsValue.Index(i) // Dereference if it's a pointer - if record.Kind() == reflect.Ptr { + if record.Kind() == reflect.Pointer { if record.IsNil() { continue } diff --git a/pkg/restheadspec/handler.go b/pkg/restheadspec/handler.go index 9d20bb0..0f2f8c8 100644 --- a/pkg/restheadspec/handler.go +++ b/pkg/restheadspec/handler.go @@ -349,7 +349,7 @@ func (h *Handler) handleRead(ctx context.Context, w common.ResponseWriter, id st // Validate and unwrap model type to get base struct modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -1892,7 +1892,7 @@ func (h *Handler) extractNestedRelations( ) (_cleanedData map[string]interface{}, _relations map[string]interface{}, _err error) { // Get model type for reflection modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -1934,7 +1934,7 @@ func (h *Handler) processChildRelationsWithParentID( ) error { // Get model type for reflection modelType := reflect.TypeOf(parentModel) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } @@ -1990,7 +1990,7 @@ func (h *Handler) processChildRelationsForField( if relatedModelType.Kind() == reflect.Slice { relatedModelType = relatedModelType.Elem() } - if relatedModelType.Kind() == reflect.Ptr { + if relatedModelType.Kind() == reflect.Pointer { relatedModelType = relatedModelType.Elem() } @@ -2413,7 +2413,7 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co modelType := reflect.TypeOf(model) // Unwrap pointers, slices, and arrays to get to the base struct type - for modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array { + for modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array { modelType = modelType.Elem() } @@ -2462,7 +2462,7 @@ func (h *Handler) generateMetadata(schema, entity string, model interface{}) *co // Check if this is a relation field (slice or struct, but not time.Time) if field.Type.Kind() == reflect.Slice || (field.Type.Kind() == reflect.Struct && field.Type.Name() != "Time") || - (field.Type.Kind() == reflect.Ptr && field.Type.Elem().Kind() == reflect.Struct && field.Type.Elem().Name() != "Time") { + (field.Type.Kind() == reflect.Pointer && field.Type.Elem().Kind() == reflect.Struct && field.Type.Elem().Name() != "Time") { metadata.Relations = append(metadata.Relations, jsonName) continue } @@ -2508,7 +2508,7 @@ func (h *Handler) getColumnType(t reflect.Type) string { return "float" case reflect.Bool: return "boolean" - case reflect.Ptr: + case reflect.Pointer: return h.getColumnType(t.Elem()) default: return "unknown" @@ -2516,7 +2516,7 @@ func (h *Handler) getColumnType(t reflect.Type) string { } func (h *Handler) isNullable(field reflect.StructField) bool { - return field.Type.Kind() == reflect.Ptr + return field.Type.Kind() == reflect.Pointer } func (h *Handler) sendResponse(w common.ResponseWriter, data interface{}, metadata *common.Metadata) { @@ -2561,7 +2561,7 @@ func (h *Handler) normalizeResultArray(data interface{}) interface{} { // Use reflection to check if data is a slice or array dataValue := reflect.ValueOf(data) - if dataValue.Kind() == reflect.Ptr { + if dataValue.Kind() == reflect.Pointer { dataValue = dataValue.Elem() } @@ -2594,7 +2594,7 @@ func (h *Handler) buildDetailFields(model interface{}) []reflection.ModelFieldDe } modelType := reflect.TypeOf(model) - for modelType != nil && (modelType.Kind() == reflect.Ptr || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { + for modelType != nil && (modelType.Kind() == reflect.Pointer || modelType.Kind() == reflect.Slice || modelType.Kind() == reflect.Array) { modelType = modelType.Elem() } if modelType == nil || modelType.Kind() != reflect.Struct { @@ -2615,7 +2615,7 @@ func (h *Handler) buildDetailFields(model interface{}) []reflection.ModelFieldDe // Skip relation fields (slices, structs that aren't time.Time, ptrs to struct) ft := field.Type - if ft.Kind() == reflect.Ptr { + if ft.Kind() == reflect.Pointer { ft = ft.Elem() } if ft.Kind() == reflect.Slice || @@ -2647,7 +2647,7 @@ func (h *Handler) buildDetailFields(model interface{}) []reflection.ModelFieldDe sqlKey = "unique" } - nullable := field.Type.Kind() == reflect.Ptr + nullable := field.Type.Kind() == reflect.Pointer if strings.Contains(gormLower, "not null") { nullable = false } else if strings.Contains(gormLower, "nullable") || strings.Contains(gormLower, ",null") { @@ -3015,7 +3015,7 @@ func (h *Handler) buildFilterSQL(filter *common.FilterOption, tableName string) func (h *Handler) setRowNumbersOnRecords(records any, offset int) { // Get the reflect value of the records recordsValue := reflect.ValueOf(records) - if recordsValue.Kind() == reflect.Ptr { + if recordsValue.Kind() == reflect.Pointer { recordsValue = recordsValue.Elem() } @@ -3030,7 +3030,7 @@ func (h *Handler) setRowNumbersOnRecords(records any, offset int) { record := recordsValue.Index(i) // Dereference if it's a pointer - if record.Kind() == reflect.Ptr { + if record.Kind() == reflect.Pointer { if record.IsNil() { continue } @@ -3085,7 +3085,7 @@ func (h *Handler) filterExtendedOptions(validator *common.ColumnValidator, optio // Filter Expand columns using the expand relation's model filteredExpands := make([]ExpandOption, 0, len(options.Expand)) modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } diff --git a/pkg/restheadspec/headers.go b/pkg/restheadspec/headers.go index 94d2ee0..5cbe8df 100644 --- a/pkg/restheadspec/headers.go +++ b/pkg/restheadspec/headers.go @@ -977,7 +977,7 @@ func (h *Handler) resolveRelationName(model interface{}, nameOrTable string) str } // Dereference pointer if needed - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } @@ -1012,13 +1012,13 @@ func (h *Handler) resolveRelationName(model interface{}, nameOrTable string) str var targetType reflect.Type if fieldType.Kind() == reflect.Slice { targetType = fieldType.Elem() - } else if fieldType.Kind() == reflect.Ptr { + } else if fieldType.Kind() == reflect.Pointer { targetType = fieldType.Elem() } if targetType != nil { // Dereference pointer if the slice contains pointers - if targetType.Kind() == reflect.Ptr { + if targetType.Kind() == reflect.Pointer { targetType = targetType.Elem() } @@ -1062,7 +1062,7 @@ func (h *Handler) resolveRelationNameWithJoinKey(model interface{}, nameOrTable if modelType == nil { return nameOrTable } - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } if modelType == nil || modelType.Kind() != reflect.Struct { @@ -1089,10 +1089,10 @@ func (h *Handler) resolveRelationNameWithJoinKey(model interface{}, nameOrTable var targetType reflect.Type if fieldType.Kind() == reflect.Slice { targetType = fieldType.Elem() - } else if fieldType.Kind() == reflect.Ptr { + } else if fieldType.Kind() == reflect.Pointer { targetType = fieldType.Elem() } - if targetType != nil && targetType.Kind() == reflect.Ptr { + if targetType != nil && targetType.Kind() == reflect.Pointer { targetType = targetType.Elem() } if targetType == nil || targetType.Kind() != reflect.Struct { diff --git a/pkg/security/hooks.go b/pkg/security/hooks.go index f7ad683..52138d8 100644 --- a/pkg/security/hooks.go +++ b/pkg/security/hooks.go @@ -90,7 +90,7 @@ func applyRowSecurity(secCtx SecurityContext, securityList *SecurityList) error // Get primary key name from model modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } @@ -155,13 +155,13 @@ func applyColumnSecurity(secCtx SecurityContext, securityList *SecurityList) err // Get model type modelType := reflect.TypeOf(model) - if modelType.Kind() == reflect.Ptr { + if modelType.Kind() == reflect.Pointer { modelType = modelType.Elem() } // Apply column security masking resultValue := reflect.ValueOf(result) - if resultValue.Kind() == reflect.Ptr { + if resultValue.Kind() == reflect.Pointer { resultValue = resultValue.Elem() } diff --git a/pkg/websocketspec/handler.go b/pkg/websocketspec/handler.go index 317410f..4f7c3fe 100644 --- a/pkg/websocketspec/handler.go +++ b/pkg/websocketspec/handler.go @@ -840,7 +840,7 @@ func (h *Handler) buildFilterCondition(filter common.FilterOption) (conditionStr func (h *Handler) setRowNumbersOnRecords(records interface{}, offset int) { // Get the reflect value of the records recordsValue := reflect.ValueOf(records) - if recordsValue.Kind() == reflect.Ptr { + if recordsValue.Kind() == reflect.Pointer { recordsValue = recordsValue.Elem() } @@ -855,7 +855,7 @@ func (h *Handler) setRowNumbersOnRecords(records interface{}, offset int) { record := recordsValue.Index(i) // Dereference if it's a pointer - if record.Kind() == reflect.Ptr { + if record.Kind() == reflect.Pointer { if record.IsNil() { continue }