Incorrect ArangoDB API Usage & Idempotency in createCollection Helper
Describe the bug The Person struct, which is used for handling user data, is defined directly within the CreateUserHandler function. This approach restricts its scope and reusability, making the code less modular and harder to maintain if the same Person structure needs to be used elsewhere (e.g., in other handlers, for database operations, or for data serialization/deserialization). It's a code organization and best practice issue rather than a runtime crash. To Reproduce Steps to reproduce the behavior, if applicable: Steps to reproduce the behavior, if applicable:
The code in question is found in the CreateUserHandler function, specifically:
Go
func CreateUserHandler(ctx gofr.Context) (interface{}, error) {
// Create a person document
type Person struct {
Name string json:"name"
Age int json:"age"
}
// ... rest of the handler logic
}
There is no runtime error generated by this specific bug; it's a structural issue. However, if you attempt to use the Person struct outside of this function, it will result in a compilation error:
undefined: Person
Expected behavior The Person struct should be defined at a package level (e.g., in main.go or a dedicated models.go file within the package). This makes it accessible and reusable across different functions and files in the package, leading to cleaner, more maintainable, and less redundant code.
for example Go
package main
// Person struct defined at package level
type Person struct {
Name string json:"name"
Age int json:"age"
}
func CreateUserHandler(ctx gofr.Context) (interface{}, error) { var p Person // Use the package-level struct // ... rest of the handler logic }
Screenshots
**Environments ** -OS: Linux (or any OS)
- gofr version [v1.5.0]
- go version [1.21]
More description Defining structs at the package level is a standard Go best practice for data structures that represent domain entities or are used in multiple contexts. This improves code readability, reusability, and makes it easier to manage data models.
i am enrolled in gofr summer of code please assign it to me
Sure you can work on it.
@ayushhhh2999 you working on this? need any help?
@ayushhhh2999, Unassigning you. SInce there has been no activity.
@coolwednesday @ayushhhh2999 Thank you for pointing this out. I don’t believe this is an issue that requires a fix. Your observation would certainly hold true in the case of a full-fledged project. However, since this is intended purely as an example for ArangoDB, all the necessary functions and structs have been defined within the same file and scoped to the function for simplicity. The example is meant to demonstrate usage and consumption of ArangoDB, which is already well covered here.
assign me this , i am ready to work for it
@coolwednesday if its issue is not resolve then i am ready to contributing on that