Skip to content

Conversation

@epicgdog
Copy link

This PR introduces the foundation of a Go backend for the SCEats project, implementing a database connection and a basic REST API. The project is organized into distinct internal packages for database management and http services, adhering to Go’s best practices for package structuring.

db *sql.DB
}

func toInt(barcode string) (int64, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a redundant function because the function it wraps already does the thing it aims to wrap.

_ "github.com/mattn/go-sqlite3"
)

func getProductInfo(barcode_num string) (map[string]interface{}, error) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return a structure not interface. Returning an interface is equivalent of using any in typescript.


err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use either fmt or log, don't use both for consistency sake.

return
}

c.JSON(200, gin.H{"message": "added item " + request.Barcode + " " + "(" + request.Name + ")"})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use fmt here

validUsername := os.Getenv("AUTH_USERNAME")
validPassword := os.Getenv("AUTH_PASSWORD")

println(request.Password + " " + request.Username)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use log or fmt

println(validUsername + " " + validPassword)

// Check if the credentials are correct
if request.Username == validUsername && request.Password == validPassword {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably be decouples into its own function

return
}

err := godotenv.Load()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you already load this once outside of this function, you dont need to load it again


func UseItemRoutes(router *gin.RouterGroup, food *database.FoodItems) {
router.GET("/items", func(c *gin.Context) {
HandleGetAllItems(c, food)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a good, but you an use a different wrapping methodology, to get rid of the surrounding func(c *gin.Context) {}

ex:

func HandleGetAllItems(c *gin.Context, food *database.FoodItems) func(c *gin.Context) {

return func(c *gin.Context) {
...
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants