Search code examples
gourlquery-stringrevel

How to read query parameters in Revel using the 'routes' file?


I am new to Revel and golang. I need help as to how can I access query paramters in Revel and configure it in routes.

Example: localhost:9000/company?name=ABC.

I am sending above get request to fetch the company by name from database. I don't know how can I configure it in the routes file.

My action has

func (c APP) ShowByName(name string){..}

This is how I have set the routes:

GET /company?name:name      APP.ShowByName

Solution

  • I found solution to this.

    In action I placed the below code :

    c.Params.Query=c.Request.URL.Query()
    var limit int
    c.Params.Bind(&limit,"limit")
    

    and it work for the below URL:

    localhost:9000?limit=21
    

    Here is the complete code for that revel read query parameter