livebud / bud

The Full-Stack Web Framework for Go
MIT License
5.58k stars 179 forks source link

How to use rearmost part of url as parameter? #411

Closed mateo-ivc closed 1 year ago

mateo-ivc commented 1 year ago

Hi there,

Let's say i have a controller that listens at example.com/posts/ How can I use the Index function in my posts/controller.go to listen to all calls like example.com/posts/ ?

Thanks in advance :)

matthewmueller commented 1 year ago

Hey @zepnex

Can you share some code? And the request you're trying to make?

Two things to try based on what you said:

  1. Are you using functions or methods? Bud expects methods (e.g. func (c *Controller) Index() {})
  2. Or do you specifically mean it's not routing with the trailing slash /?
mateo-ivc commented 1 year ago

Hey @matthewmueller

Sorry my previous post is missing a significant information 😅

I dont have any specific code right now. But what i basically mean is that i want to have a method in my posts/controller.go like func (c *Controller) Index() {} Which works like example.com/posts/:id but with a string instead. When I search for example.com/posts/Filter-Coffee its should server me with the content of the Story "Filter-Coffee", when example.com/posts/Go-Bud then with the content of "Go-Bud". But they all should be handled over one method.

And I am using methods sorry for the confusion 😅

mateo-ivc commented 1 year ago

Hi its me again 😅

It's a little bit awkward to admit, but the problem I described is not really a problem :D Basically what i searched for was the Show() methode. I don't know why but in my world this methode was only working with integers :D. But I know that I can also use it for string etc.

Sorry for the unnecessary issue 😅