gin-gonic / gin

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.
https://gin-gonic.com/
MIT License
78.96k stars 8.02k forks source link

question: Please tell me the meaning of 255. #2583

Open itcuihao opened 3 years ago

itcuihao commented 3 years ago

Description

How to reproduce

func countParams(path string) uint8 {
    var n uint
    for i := 0; i < len(path); i++ {
        if path[i] != ':' && path[i] != '*' {
            continue
        }
        n++
    }
    if n >= 255 {
        return 255
    }
    return uint8(n)
}
Doarakko commented 3 years ago

uint8 is unsigned integer 8 bit. 8 bits can represent 0 to 255(2**8-1)

itcuihao commented 3 years ago

Does it mean that the length of path cannot exceed 255? Why is it so set?

cpl commented 3 years ago

If I am reading the function correctly, it's counting the named params (:name, :id in the defined path) and not the path length. Check the function usage to understand the possible limtations around it.

yeqown commented 3 years ago

there isn't 255 anymore 😂

https://github.com/gin-gonic/gin/blob/b01605bb5b43dbf33781970af5ad6633e5549fd1/tree_test.go#L87-94