Slide is one of the fastest frameworks, built on top of fasthttp. People coming form express will feel at home.
While playing around with the Go’s net/http, one thing that we missed most was the lack of middleware support and the problems it solves. After a little reading, we decided to write our own web framework which would solve the issues like middleware support with next, handle a wide range of files, Upload, Download, etc.
💡 Note: We are still in experimental stage, would love to hear feedback.
go get -u github.com/go-slide/slide
For more API information check Docs
package main
import (
"log"
"github.com/go-slide/slide"
"github.com/go-playground/validator/v10"
)
func main() {
validate := validator.New()
config := slide.Config{
Validator: validate,
}
app := slide.InitServer(&config)
app.Get("/", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})
log.Fatal(app.Listen("localhost:4321"))
}
Slide supports multilevel routing.
app := slide.InitServer(&config)
app.Get("/", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})
// Grouping your route
auth := app.Group("/auth")
auth.Get("/login", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})
Slide supports wide range of middlewares.
- Application Level
- Group Level
- Route Level
app := slide.InitServer(&config)
## Application level
app.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all URL(s)")
return ctx.Next()
})
//Group Level
auth := app.Group("/auth")
auth.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all /auth URL(s)")
return ctx.Next()
})
auth.Get("/login", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})
// Route level, works in Right -> Left or Bottom to Top
app.Get("/routermiddleware", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "hola!")
}, func(ctx *slide.Ctx) error {
fmt.Println("this prints second", ctx.RequestCtx.UserValue("lol"))
return ctx.Next()
}, func(ctx *slide.Ctx) error {
fmt.Println("this prints first")
return ctx.Next()
})
autocannon -c 100 -d 40 -p http://localhost:4321/
Framework | No of requests |
---|---|
Slide | 2765K |