Here is simple code that i am trying
package main
import (
"log"
"github.com/gin-gonic/gin"
)
func main() {
server := gin.Default()
server.GET("/countries/*code", GetCountries)
server.Run()
}
func GetCountries(c *gin.Context) {
ccode := c.Param("code")
log.Printf("Code: %s", ccode)
}
I have extracted code from url and log it. Here is output after running and accessing urls
[GIN-debug] redirecting request 301: /countries --> /countries/
Code: /
[GIN] 2016/07/16 - 17:24:59 | 200 | 16.508��s | ::1 | GET /countries/
Code: /USA
[GIN] 2016/07/16 - 17:25:17 | 200 | 12.47��s | ::1 | GET /countries/USA
In output, you can see, it is giving code along with the "/". If there is no code in url still it is giving "/"
Is it a bug or expected behaviour of gin? Do i need to check for "/" to know whether code is actually passed or not?