mirror of
https://github.com/gofiber/fiber.git
synced 2025-04-27 13:14:31 +00:00
Rename / Add middleware
This commit is contained in:
parent
bd2e034c49
commit
5283fb8f37
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"
|
"github.com/gofiber/fiber"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Morgan : Simple logger
|
// Logger : Simple logger
|
||||||
func Morgan() func(*fiber.Ctx) {
|
func Logger() func(*fiber.Ctx) {
|
||||||
return func(c *fiber.Ctx) {
|
return func(c *fiber.Ctx) {
|
||||||
currentTime := time.Now().Format("02 Jan, 15:04:05")
|
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"))
|
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 * always set the path to the wildcard parameter
|
||||||
if route.Wildcard {
|
if route.Wildcard {
|
||||||
ctx.params = &[]string{"*"}
|
ctx.params = &[]string{"*"}
|
||||||
ctx.values = []string{path}
|
ctx.values = make([]string, 1)
|
||||||
|
ctx.values[0] = path
|
||||||
}
|
}
|
||||||
found = true
|
found = true
|
||||||
// Set route pointer if user wants to call .Route()
|
// 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 we have matches, add params and values to context
|
||||||
if len(matches) > 0 && len(matches[0]) > 1 {
|
if len(matches) > 0 && len(matches[0]) > 1 {
|
||||||
ctx.params = &route.Params
|
ctx.params = &route.Params
|
||||||
|
// ctx.values = make([]string, len(*ctx.params))
|
||||||
ctx.values = matches[0][1:len(matches[0])]
|
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 .
|
// See https://groups.google.com/forum/#!msg/Golang-Nuts/ENgbUzYvCuU/90yGx7GUAgAJ .
|
||||||
func getBytes(s string) (b []byte) {
|
func getBytes(s string) (b []byte) {
|
||||||
// return *(*[]byte)(unsafe.Pointer(&s))
|
// return *(*[]byte)(unsafe.Pointer(&s))
|
||||||
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
|
||||||
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
|
sh := *(*reflect.StringHeader)(unsafe.Pointer(&s))
|
||||||
bh.Data = sh.Data
|
bh := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
bh.Len = sh.Len
|
bh.Data, bh.Len, bh.Cap = sh.Data, sh.Len, sh.Len
|
||||||
bh.Cap = sh.Len
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user