-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from go-slide/feature/core/updated-readme
updated readme
- Loading branch information
Showing
4 changed files
with
103 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
[](https://codecov.io/gh/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** | ||
|
||
[](https://codecov.io/gh/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 | ||
 | ||
## 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters