diff --git a/middleware/csrf.go b/middleware/csrf.go new file mode 100644 index 00000000..29502495 --- /dev/null +++ b/middleware/csrf.go @@ -0,0 +1,12 @@ +package middleware + +import ( + "github.com/gofiber/fiber" +) + +// CSRF : +func CSRF() func(*fiber.Ctx) { + return func(c *fiber.Ctx) { + c.Next() + } +} diff --git a/middleware/limiter.go b/middleware/limiter.go new file mode 100644 index 00000000..06eb87f2 --- /dev/null +++ b/middleware/limiter.go @@ -0,0 +1,12 @@ +package middleware + +import ( + "github.com/gofiber/fiber" +) + +// Session : +func Session() func(*fiber.Ctx) { + return func(c *fiber.Ctx) { + c.Next() + } +} diff --git a/middleware/morgan.go b/middleware/logger.go similarity index 83% rename from middleware/morgan.go rename to middleware/logger.go index 38f21c50..46e047cb 100644 --- a/middleware/morgan.go +++ b/middleware/logger.go @@ -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")) diff --git a/middleware/session.go b/middleware/session.go new file mode 100644 index 00000000..06eb87f2 --- /dev/null +++ b/middleware/session.go @@ -0,0 +1,12 @@ +package middleware + +import ( + "github.com/gofiber/fiber" +) + +// Session : +func Session() func(*fiber.Ctx) { + return func(c *fiber.Ctx) { + c.Next() + } +} diff --git a/router.go b/router.go index fba5506d..8bc6bcc7 100644 --- a/router.go +++ b/router.go @@ -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])] } } diff --git a/utils.go b/utils.go index 963623b2..88e5aaa5 100644 --- a/utils.go +++ b/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 }