Skip to content

Commit

Permalink
Merge pull request #36 from go-slide/feature/core/updated-readme
Browse files Browse the repository at this point in the history
updated readme
  • Loading branch information
go-slide authored Aug 9, 2020
2 parents eb37474 + a9440f5 commit c69a5ff
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 115 deletions.
194 changes: 103 additions & 91 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,114 +1,126 @@
# slide-go
# Slide, a Go web framework for Building API(s)

## Installation
[![codecov](https://codecov.io/gh/go-slide/slide/branch/master/graph/badge.svg)](https://codecov.io/gh/go-slide/slide)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-slide/slide)](https://goreportcard.com/report/github.com/go-slide/slide)

###### tags: `Go` `Express`

> Slide is one of the fastest framework, built on top of fasthttp.
> People coming form express will feel at home.

## Motivation
Whlie 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 wide range of files, Upload, Download etc.


**:bulb: **Note:** We are still in experimental stage, would love to hear feedback.**


### Installation
```cmd
go get -u github.com/go-slide/slide
```
**Not Production Ready**

[![codecov](https://codecov.io/gh/go-slide/slide/branch/master/graph/badge.svg)](https://codecov.io/gh/go-slide/slide)
[![Go Report Card](https://goreportcard.com/badge/github.com/go-slide/slide)](https://goreportcard.com/report/github.com/go-slide/slide)
### :rocket: Example

## Example
For more API information check [Docs](https://goslide-framework.gitbook.io/slide/)

```go
package main

import (
"fmt"
"github.com/go-slide/slide/middleware"
"log"
"net/http"

"github.com/go-slide/slide"

"github.com/go-playground/validator/v10"
)

type Login struct {
Username string `json:"username" validate:"required"`
Password string `json:"password" validate:"required"`
}


func main() {
validate := validator.New()
validate := validator.New()
config := slide.Config{
Validator: validate,
}

app := slide.InitServer(&config)

// compression middleware
app.Use(middleware.Compress())

// this is with config
app.Use(middleware.CorsWithConfig(middleware.CorsConfig{
AllowOrigins: []string{"https://www.postgresqltutorial.com"},
}))

// you can multiple middlewares also
app.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all URL(s)")
return ctx.Next()
})

app.Get("/", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})

// redirect to new url
app.Get("/redirect", func(ctx *slide.Ctx) error {
return ctx.Redirect(http.StatusTemporaryRedirect, "http://localhost:3000/static")
})

app.Get("/name/:name", func(ctx *slide.Ctx) error {
name := ctx.GetParam("name")
return ctx.Send(http.StatusOK, fmt.Sprintf("hello, %s", name))
})

app.Post("/login", func(ctx *slide.Ctx) error {
login := Login{}
err := ctx.Bind(&login)
if err != nil {
return err
}
return ctx.Json(http.StatusOK, map[string]string{
"message": fmt.Sprintf("Welcome %s", login.Username),
})
})

// Grouping your route
auth := app.Group("/auth")
// you can multiple middlewares also
auth.Use(func(ctx *slide.Ctx) error {
fmt.Println("this will run for all urls with /auth")
return ctx.Next()
})
auth.Get("/login", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})

// path and dir name
app.ServerDir("/static", "static")

// single file
app.ServeFile("/js", "static/login.js")

// Downloading file
app.Get("/download", func(ctx *slide.Ctx) error {
return ctx.SendAttachment("static/login.js", "login.js")
})

// uploading file
app.Post("/upload", func(ctx *slide.Ctx) error {
return ctx.UploadFile("static/login.js", "login.js")
})

log.Fatal(app.Listen("localhost:3000"))
app := slide.InitServer(&config)
app.Get("/", func(ctx *slide.Ctx) error {
return ctx.Send(http.StatusOK, "Hello, World")
})
log.Fatal(app.Listen("localhost:4321"))
}
```

## Benchmarks
![](https://i.ibb.co/TWdgzB8/slide-benchmark.png)
## Routing

Slide supports multilevel routing.

```go
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.
1. Application Level
2. Group Level
3. Route Level

```go
app := slide.InitServer(&config)

## Application level
// you can multiple middlewares also
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
// you can have router level middleware which 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

```cmd
autocannon -c 100 -d 40 -p http://localhost:4321/
```

| Framework | No of requests |
| -------- | -------- |
| Slide | 2765K |




**:computer: Core Contributors**
[Sai Umesh](https://twitter.com/saiumesh)
[Madhuri](https://twitter.com/pittalamadhuri)
1 change: 0 additions & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ func main() {
return ctx.Next()
}, func(ctx *slide.Ctx) error {
fmt.Println("this prints first")
ctx.RequestCtx.SetUserValue("lol", "wtf")
return ctx.Next()
})

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ require (
github.com/go-playground/validator/v10 v10.3.0
github.com/stretchr/testify v1.6.1
github.com/valyala/fasthttp v1.14.0
golang.org/x/lint v0.0.0-20200302205851-738671d3881b // indirect
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a // indirect
)
21 changes: 0 additions & 21 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,37 +27,16 @@ github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyC
github.com/valyala/fasthttp v1.14.0 h1:67bfuW9azCMwW/Jlq/C+VeihNpAuJMWkYPBig1gdi3A=
github.com/valyala/fasthttp v1.14.0/go.mod h1:ol1PCaL0dX20wC0htZ7sYCsvCYmrouYra0zHzaclZhE=
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b h1:Wh+f8QHJXR411sJR8/vRBTZ7YapZaRvUcLFFJhusH0k=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e h1:3G+cUijn7XD+S4eJFddp53Pv7+slrESplyjG25HgL+k=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 h1:EBZoQjiKKPaLbPrbpssUfuHtwM6KV/vb4U85g/cigFY=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a h1:kVMPw4f6EVqYdfGQTedjrpw1dbE2PEMfw4jwXsNdn9s=
golang.org/x/tools v0.0.0-20200721032237-77f530d86f9a/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
Expand Down

0 comments on commit c69a5ff

Please sign in to comment.