From 7e90187a3ba0f0a28f383f0a0b31b8d37ab220b9 Mon Sep 17 00:00:00 2001 From: Daniel Szasz Date: Thu, 19 Dec 2024 08:11:37 +0200 Subject: [PATCH] Change the default path for CRUD helpers to be lower case (#1276) If the structure contains a capital letter the default path will contain also the capital letter. Since path are case sensitive only on some servers it creates confusion. To avoid it, the paths in the url's are converted to lower case. --- pkg/gofr/crud_handlers_test.go | 12 +++++++++--- pkg/gofr/crud_helpers.go | 2 +- pkg/gofr/datasource/README.md | 34 ++++++++++++++++------------------ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/pkg/gofr/crud_handlers_test.go b/pkg/gofr/crud_handlers_test.go index f6a20b7c8..00d0f9db6 100644 --- a/pkg/gofr/crud_handlers_test.go +++ b/pkg/gofr/crud_handlers_test.go @@ -76,7 +76,7 @@ func Test_scanEntity(t *testing.T) { entityType: reflect.TypeOf(userTestEntity{}), primaryKey: "id", tableName: "user_test_entity", - restPath: "userTestEntity", + restPath: "usertestentity", constraints: map[string]gofrSql.FieldConstraints{"id": {AutoIncrement: true, NotNull: false}, "name": {AutoIncrement: false, NotNull: true}, }, @@ -180,10 +180,16 @@ func Test_getRestPath(t *testing.T) { want: "custom_path", }, { - name: "Test without RestPathOverrider interface", + name: "Test without RestPathOverrider interface - with lower case transformation", object: &struct{}{}, structName: "TestStruct", - want: "TestStruct", + want: "teststruct", + }, + { + name: "Test without RestPathOverrider interface", + object: &struct{}{}, + structName: "test_struct", + want: "test_struct", }, } for _, tt := range tests { diff --git a/pkg/gofr/crud_helpers.go b/pkg/gofr/crud_helpers.go index 03545c593..4bbb83bf5 100644 --- a/pkg/gofr/crud_helpers.go +++ b/pkg/gofr/crud_helpers.go @@ -21,7 +21,7 @@ func getRestPath(object any, structName string) string { return v.RestPath() } - return structName + return strings.ToLower(structName) } func hasAutoIncrementID(constraints map[string]sql.FieldConstraints) bool { diff --git a/pkg/gofr/datasource/README.md b/pkg/gofr/datasource/README.md index 53bc33469..7c4a93605 100644 --- a/pkg/gofr/datasource/README.md +++ b/pkg/gofr/datasource/README.md @@ -69,21 +69,19 @@ Therefore, GoFr utilizes a pluggable approach for new datasources by separating ## Supported Datasources -| Datasource | Health-Check | Logs | Metrics | Traces | As Driver | -|-----------------|--------------|------|---------|--------|-----------| -| MySQL | ✅ | ✅ | ✅ | ✅ | | -| Redis | ✅ | ✅ | ✅ | ✅ | | -| PostgreSQL | ✅ | ✅ | ✅ | ✅ | | -| MongoDB | ✅ | ✅ | ✅ | ✅ | ✅ | -| SQLite | ✅ | ✅ | ✅ | ✅ | | -| BadgerDB | ✅ | ✅ | ✅ | ✅ | ✅ | -| Cassandra | ✅ | ✅ | ✅ | ✅ | ✅ | -| ClickHouse | | ✅ | ✅ | ✅ | ✅ | -| FTP | | ✅ | | | ✅ | -| SFTP | | ✅ | | | ✅ | -| Solr | | ✅ | ✅ | ✅ | ✅ | -| Dgraph | ✅ | ✅ | ✅ | ✅ | | -| Azure Event Hub | | ✅ | ✅ | | ✅ | -| OpenTSDB | ✅ | ✅ | | ✅ | ✅ | - - +| Datasource | Health-Check | Logs | Metrics | Traces | As Driver | +|------------------|:------------:|:----:|:-------:|:------:|:---------:| +| MySQL | ✅ | ✅ | ✅ | ✅ | | +| REDIS | ✅ | ✅ | ✅ | ✅ | | +| PostgreSQL | ✅ | ✅ | ✅ | ✅ | | +| MongoDB | ✅ | ✅ | ✅ | ✅ | ✅ | +| SQLite | ✅ | ✅ | ✅ | ✅ | | +| BadgerDB | ✅ | ✅ | ✅ | ✅ | ✅ | +| Cassandra | ✅ | ✅ | ✅ | ✅ | ✅ | +| ClickHouse | | ✅ | ✅ | ✅ | ✅ | +| FTP | | ✅ | | | ✅ | +| SFTP | | ✅ | | | ✅ | +| Solr | | ✅ | ✅ | ✅ | ✅ | +| DGraph | ✅ | ✅ | ✅ | ✅ | | +| Azure Event Hubs | | ✅ | ✅ | |✅ | +| OpenTSDB | ✅ | ✅ | | ✅ | ✅ |