Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3b94964068 | |||
| 1dba802590 |
39
README.md
39
README.md
@@ -1,8 +1,8 @@
|
||||
# Sux
|
||||
|
||||
Static route http router that considers the request method with support for parameters, middleware, and route groups.
|
||||
HTTP router that considers the request method with support for parameters, middleware, and route groups.
|
||||
|
||||
Useful for serving server-side rendered content.
|
||||
Useful for serving all kinds of content.
|
||||
|
||||
## Features
|
||||
|
||||
@@ -52,22 +52,22 @@ r := sux.New()
|
||||
// Named parameters
|
||||
r.GET("/users/:id", func(w http.ResponseWriter, r *http.Request) {
|
||||
params := sux.ParamsFromContext(r)
|
||||
id := params["id"]
|
||||
id := params.Get("id")
|
||||
io.WriteString(w, "User ID: "+id)
|
||||
})
|
||||
|
||||
// Wildcard parameters (captures rest of path)
|
||||
r.GET("/files/*path", func(w http.ResponseWriter, r *http.Request) {
|
||||
params := sux.ParamsFromContext(r)
|
||||
path := params["path"]
|
||||
path := params.Get("path")
|
||||
io.WriteString(w, "File path: "+path)
|
||||
})
|
||||
|
||||
// Multiple parameters
|
||||
r.GET("/users/:userId/posts/:postId", func(w http.ResponseWriter, r *http.Request) {
|
||||
params := sux.ParamsFromContext(r)
|
||||
userId := params["userId"]
|
||||
postId := params["postId"]
|
||||
userId := params.Get("userId")
|
||||
postId := params.Get("postId")
|
||||
io.WriteString(w, "User "+userId+", Post "+postId)
|
||||
})
|
||||
```
|
||||
@@ -187,32 +187,7 @@ BenchmarkLargeRouter-8 1548286 833.0 ns/op 704 B/op 9 alloc
|
||||
|
||||
### Performance Comparison
|
||||
|
||||
Compared to other popular Go routers:
|
||||
|
||||
```
|
||||
darko@arch ~ $ wrk -c1000 -t8 -d30s http://inuc:8080/
|
||||
Running 30s test @ http://inuc:8080/
|
||||
8 threads and 1000 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 7.08ms 3.02ms 64.38ms 89.40%
|
||||
Req/Sec 18.24k 2.11k 24.06k 73.88%
|
||||
4260394 requests in 30.00s, 491.63MB read
|
||||
Requests/sec: 142025.60
|
||||
Transfer/sec: 16.39MB
|
||||
```
|
||||
|
||||
Compared to https://github.com/julienschmidt/httprouter
|
||||
```
|
||||
darko@arch ~ $ wrk -c1000 -t8 -d30s http://inuc:8080/
|
||||
Running 30s test @ http://inuc:8080/
|
||||
8 threads and 1000 connections
|
||||
Thread Stats Avg Stdev Max +/- Stdev
|
||||
Latency 7.14ms 3.13ms 74.06ms 89.99%
|
||||
Req/Sec 18.18k 2.19k 23.31k 75.88%
|
||||
4224358 requests in 30.00s, 487.47MB read
|
||||
Requests/sec: 140826.15
|
||||
Transfer/sec: 16.25MB
|
||||
```
|
||||
see [COMPARISON.md](COMPARISON.md)
|
||||
|
||||
## API Reference
|
||||
|
||||
|
||||
Reference in New Issue
Block a user