mirror of
https://github.com/gofiber/fiber.git
synced 2025-02-24 03:43:51 +00:00
commit
22db014a41
12
middleware/csrf.go
Normal file
12
middleware/csrf.go
Normal 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
12
middleware/limiter.go
Normal 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()
|
||||
}
|
||||
}
|
@ -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
12
middleware/session.go
Normal 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()
|
||||
}
|
||||
}
|
@ -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])]
|
||||
}
|
||||
}
|
||||
|
6
utils.go
6
utils.go
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user