Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

router two parameters #402

Closed
rawoke083 opened this issue Aug 11, 2015 · 3 comments
Closed

router two parameters #402

rawoke083 opened this issue Aug 11, 2015 · 3 comments
Labels

Comments

@rawoke083
Copy link

HI
Is it possible to do a route like this

//route 1
r.Get("/product/:id/)

//route 2
r.Get("/product/:id/shop/:shopid")
@rawoke083
Copy link
Author

Anyone :( ?

@ironiridis
Copy link
Contributor

Yes.

charrington@localhost ~/go/tmp $ cat test.go
package main

import "github.com/gin-gonic/gin"
import "log"

func main() {
  router := gin.Default()
  router.GET("/a/:a", func(c *gin.Context) {
    a1 := c.Param("a")
    log.Printf("/a/:a route invoked. a=%q\n", a1);
  });
  router.GET("/a/:a/b/:b", func(c *gin.Context) {
    a2 := c.Param("a")
    b2 := c.Param("b")
    log.Printf("/a/:a/b/:b route invoked. a=%q, b=%q\n", a2, b2);
  });
  router.Run(":8080")
}
charrington@localhost ~/go/tmp $ go run test.go
[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.
 - using env:   export GIN_MODE=release
 - using code:  gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET   /a/:a                     --> main.func·001 (3 handlers)
[GIN-debug] GET   /a/:a/b/:b                --> main.func·002 (3 handlers)
[GIN-debug] Listening and serving HTTP on :8080
/a/:a route invoked. a="Apple"
[GIN] 2015/08/13 - 16:05:47 | 200 |    1.194896ms | 10.10.10.1:60526 |   GET     /a/Apple
/a/:a/b/:b route invoked. a="Apple", b="Banana"
[GIN] 2015/08/13 - 16:05:50 | 200 |     464.636µs | 10.10.10.1:60527 |   GET     /a/Apple/b/Banana
[GIN] 2015/08/13 - 16:06:05 | 404 |       3.229µs | 10.10.10.1:60528 |   GET     /a/Apple/b/
/a/:a/b/:b route invoked. a="", b="Boat"
[GIN] 2015/08/13 - 16:06:17 | 200 |    1.077709ms | 10.10.10.1:60529 |   GET     /a//b/Boat
[GIN] 2015/08/13 - 16:06:28 | 404 |       3.646µs | 10.10.10.1:60530 |   GET     /a//b/

@manucorporat
Copy link
Contributor

@rawoke083 yes, it can be done.

[GIN-debug] GET   /product/:id/             --> main.handler (3 handlers)
[GIN-debug] GET   /product/:id/shop/:shopid --> main.handler (3 handlers)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants