1
0
mirror of https://github.com/gofiber/fiber.git synced 2025-02-24 03:43:51 +00:00

Merge pull request #43 from Fenny/master

Rename / Add middleware
This commit is contained in:
Fenny 2020-02-05 05:55:26 -05:00 committed by GitHub
commit 22db014a41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 7 deletions

12
middleware/csrf.go Normal file
View File

@ -0,0 +1,12 @@
package middleware
import (
"github.com/gofiber/fiber"
)
// CSRF :
func CSRF() func(*fiber.Ctx) {
return func(c *fiber.Ctx) {
c.Next()
}
}

12
middleware/limiter.go Normal file
View File

@ -0,0 +1,12 @@
package middleware
import (
"github.com/gofiber/fiber"
)
// Session :
func Session() func(*fiber.Ctx) {
return func(c *fiber.Ctx) {
c.Next()
}
}

View File

@ -7,8 +7,8 @@ import (
"github.com/gofiber/fiber"
)
// Morgan : Simple logger
func Morgan() func(*fiber.Ctx) {
// Logger : Simple logger
func Logger() func(*fiber.Ctx) {
return func(c *fiber.Ctx) {
currentTime := time.Now().Format("02 Jan, 15:04:05")
fmt.Printf("%s \x1b[1;32m%s \x1b[1;37m%s\x1b[0000m, %s\n", currentTime, c.Method(), c.Path(), c.Get("User-Agent"))

12
middleware/session.go Normal file
View File

@ -0,0 +1,12 @@
package middleware
import (
"github.com/gofiber/fiber"
)
// Session :
func Session() func(*fiber.Ctx) {
return func(c *fiber.Ctx) {
c.Next()
}
}

View File

@ -124,7 +124,8 @@ func (r *Fiber) handler(fctx *fasthttp.RequestCtx) {
// If * always set the path to the wildcard parameter
if route.Wildcard {
ctx.params = &[]string{"*"}
ctx.values = []string{path}
ctx.values = make([]string, 1)
ctx.values[0] = path
}
found = true
// Set route pointer if user wants to call .Route()
@ -170,6 +171,7 @@ func (r *Fiber) handler(fctx *fasthttp.RequestCtx) {
// If we have matches, add params and values to context
if len(matches) > 0 && len(matches[0]) > 1 {
ctx.params = &route.Params
// ctx.values = make([]string, len(*ctx.params))
ctx.values = matches[0][1:len(matches[0])]
}
}

View File

@ -94,10 +94,8 @@ func getString(b []byte) string {
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
func getBytes(s string) (b []byte) {
// return *(*[]byte)(unsafe.Pointer(&s))
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
bh.Data = sh.Data
bh.Len = sh.Len
bh.Cap = sh.Len
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
return b
}