GithubHelp home page GithubHelp logo

Route parameter converter about goyave HOT 3 CLOSED

go-goyave avatar go-goyave commented on July 24, 2024 1
Route parameter converter

from goyave.

Comments (3)

MShoaei avatar MShoaei commented on July 24, 2024

How exactly do you intend to send a struct in URI? Would you please send and example input?

from goyave.

System-Glitch avatar System-Glitch commented on July 24, 2024

@MShoaei
Let's say we have a Product struct model. The idea behind this would be to declare a route like this:

router.Get("/product/{Product}", product.Show, nil)

A request to show the Product with the ID (primary key) "4" would be:

GET /product/4

The framework would do something like this:

product := model.Product{}
database.GetConnection().First(&product, request.Params["Product"])

// Override the raw parameter with the struct
request.Params["Product"] = product

This is just a draft, and that would require the request.Params map to be changed to a map[string]interface{}, which is not ideal, but hopefully you get the idea.

The motivation behind this is that retrieving data from the database is not part of the business logic so it shouldn't be done inside the controller handler. Also, this would reduce redundancy because you currently have to write this kind of code in almost every controller handler.

from goyave.

System-Glitch avatar System-Glitch commented on July 24, 2024

I prefer to ditch this idea. It is already easy enough to retrieve the model.

from goyave.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.