gothinkster / golang-gin-realworld-example-app

Exemplary real world application built with Golang + Gin
https://realworld.io
MIT License
2.5k stars 495 forks source link

The ArticleFeed function is in ArticleRetrieve function #18

Closed w4-hanggi closed 4 years ago

w4-hanggi commented 5 years ago

Is there better way handle this conflict for wildcard?

wangzitian0 commented 4 years ago

I didn't get the point. Can you give more context?

w4-hanggi commented 4 years ago
func ArticleRetrieve(c *gin.Context) {
    slug := c.Param("slug")
    if slug == "feed" {
        ArticleFeed(c)
        return
    }
        ...
}

Like this code, due to the wildcard conflict, you have to add branch in the handler.

It looks bad, isn't it?

wangzitian0 commented 4 years ago

For the branch: In real world you will use elasticsearch? Relational database is not good at full-text index, we need reverse index? For the frame work: request.com/balabala?slug=feed, why have wildcard conflict.

w4-hanggi commented 4 years ago

router.GET("/:slug", ArticleRetrieve) ...

It's param, not query.

when the param of slug is "feed" go to ArticleFeed handler.

Please check it again.

wangzitian0 commented 4 years ago

lol, I can not answer, but here are more context https://github.com/gin-gonic/gin/issues?q=Wildcard+conflicts