wpcodevo/golang-fiber

Question about passing fibre.ctx

jmls opened this issue · 0 comments

jmls commented

Hi, total Go newbie here, so please bear with if my question is rather .. newbieish .. ;)

When you are calling (for example) the updateNote in controllers/note.controller.go you are passing in the fibre ctx , then finding and updating the db appropriate record

What if I wanted to use this code from elsewhere in my go application ? I wouldn't be able to because that code has no idea of what fibre.ctx is

Wouldn't it be better to refactor, and create a update method in a notes "service" that takes the noteid and payload as parameters ? Then the controller can use the service, and any other go program could use the same service as the id and payload are now just parameters rather than bound to the fibre ctx ?

I'm coming from a NestJS background where the best practice is to have a controller to manage the web calls, and a service that handles the business logic. The service can be re-used elsewhere in the application

Thanks for the article though, very clear and informative