mirror of
https://github.com/gin-gonic/gin.git
synced 2025-05-21 01:17:49 +08:00
Zero allocation router, first commit
This commit is contained in:
35
utils.go
35
utils.go
@ -12,6 +12,18 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
methodGET = iota
|
||||
methodPOST = iota
|
||||
methodPUT = iota
|
||||
methodAHEAD = iota
|
||||
methodOPTIONS = iota
|
||||
methodDELETE = iota
|
||||
methodCONNECT = iota
|
||||
methodTRACE = iota
|
||||
methodUnknown = iota
|
||||
)
|
||||
|
||||
type H map[string]interface{}
|
||||
|
||||
// Allows type H to be used with xml.Marshal
|
||||
@ -80,3 +92,26 @@ func lastChar(str string) uint8 {
|
||||
func nameOfFunction(f interface{}) string {
|
||||
return runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
|
||||
}
|
||||
|
||||
func codeForHTTPMethod(method string) int {
|
||||
switch method {
|
||||
case "GET":
|
||||
return methodGET
|
||||
case "POST":
|
||||
return methodPOST
|
||||
case "PUT":
|
||||
return methodPUT
|
||||
case "AHEAD":
|
||||
return methodAHEAD
|
||||
case "OPTIONS":
|
||||
return methodOPTIONS
|
||||
case "DELETE":
|
||||
return methodDELETE
|
||||
case "TRACE":
|
||||
return methodTRACE
|
||||
case "CONNECT":
|
||||
return methodCONNECT
|
||||
default:
|
||||
return methodUnknown
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user