# README
Slide, a Go web framework for Building API(s)
tags: Go
Express
Slide is one of the fastest frameworks, built on top of fasthttp. People coming form express will feel at home.
Motivation
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.
:bulb: Note: We are still in experimental stage, would love to hear feedback.
Installation
go get -u github.com/go-slide/slide
:rocket: Example
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"))
}
Routing
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")
})
Middleware
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()
})
Benchmark
autocannon -c 100 -d 40 -p http://localhost:4321/
Framework | No of requests |
---|---|
Slide | 2765K |
# Functions
InitServer -- initializing server with slide config.
# Constants
...
...
...
...
...
...
...
...
...
...
...
...
...
...
cors headers.
...
routing error messages.
...
...