These are chat archives for gin-gonic/gin

Mar 2019
Ofonime Francis
Mar 04 08:25

func (facade facade) RegisterRoute(r gin.RouterGroup) {
r.GET("/", func(c *gin.Context) {
c.String(http.StatusOK, "Service Alive")

r.GET("/all", func(c *gin.Context) {
    page := c.Query("page")

    ds := facade.promoHandler.datastore.OpenSession(context.Background())

    promos, err := ds.GetAllPromos(page)
    if err != nil {
        c.JSON(http.StatusBadRequest, common.ErrorResponse{Message: "Error retrieving promos"})
    if len(promos) == 0 {
        promos = []Promo{}
    c.JSON(http.StatusOK, promos)

I have the above code and want to write tests for it. I'm new with gin but every other method i've tried doesn't seem to work. Any ideas would be appreciated

Weerasak Chongnguluam
Mar 04 14:38

Hello I try this example

    // However, this one will match /user/john/ and also /user/john/send
    // If no other routers match /user/john, it will redirect to /user/john/
    router.GET("/user/:name/*action", func(c *gin.Context) {
        name := c.Param("name")
        action := c.Param("action")
        message := name + " is " + action
        c.String(http.StatusOK, message)

It tells If no other routers match /user/john, it will redirect to /user/john/ but when I open localhost:8080/user/john it 404 page not found. Does document not updated or I doing something wrong?