2024-03-22 15:08:24 +01:00
|
|
|
# web
|
2023-07-18 11:37:05 +00:00
|
|
|
|
2024-03-28 22:11:48 +01:00
|
|
|
A fast HTTP/1.1 web server that can sit behind a reverse proxy like `caddy` or `nginx` for HTTP 1/2/3 support.
|
2023-07-18 21:48:38 +02:00
|
|
|
|
2024-03-07 18:09:51 +01:00
|
|
|
## Features
|
|
|
|
|
2024-03-15 10:06:17 +01:00
|
|
|
- High performance
|
2024-03-07 18:17:01 +01:00
|
|
|
- Low latency
|
2024-03-28 22:11:48 +01:00
|
|
|
- Scales incredibly well with the number of routes
|
2024-03-07 18:09:51 +01:00
|
|
|
|
2023-07-18 21:48:38 +02:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
```shell
|
2024-03-22 15:08:24 +01:00
|
|
|
go get git.akyoto.dev/go/web
|
2023-07-18 21:48:38 +02:00
|
|
|
```
|
|
|
|
|
2024-03-07 18:09:51 +01:00
|
|
|
## Usage
|
2023-07-18 21:48:38 +02:00
|
|
|
|
|
|
|
```go
|
2024-03-22 15:08:24 +01:00
|
|
|
s := web.NewServer()
|
2023-07-18 21:48:38 +02:00
|
|
|
|
2024-03-07 18:17:01 +01:00
|
|
|
// Static route
|
2024-03-22 15:08:24 +01:00
|
|
|
s.Get("/", func(ctx web.Context) error {
|
2023-07-18 21:48:38 +02:00
|
|
|
return ctx.String("Hello")
|
|
|
|
})
|
|
|
|
|
2024-03-07 18:17:01 +01:00
|
|
|
// Parameter route
|
2024-03-22 15:08:24 +01:00
|
|
|
s.Get("/blog/:post", func(ctx web.Context) error {
|
2024-06-19 10:50:41 +02:00
|
|
|
return ctx.String(ctx.Request().Param("post"))
|
2023-07-22 11:54:13 +02:00
|
|
|
})
|
|
|
|
|
2024-03-07 18:17:01 +01:00
|
|
|
// Wildcard route
|
2024-03-22 15:08:24 +01:00
|
|
|
s.Get("/images/*file", func(ctx web.Context) error {
|
2024-06-19 10:50:41 +02:00
|
|
|
return ctx.String(ctx.Request().Param("file"))
|
2023-07-22 11:54:13 +02:00
|
|
|
})
|
2024-03-07 18:17:01 +01:00
|
|
|
|
2024-06-22 13:41:43 +02:00
|
|
|
// Middleware
|
|
|
|
s.Use(func(ctx web.Context) error {
|
|
|
|
start := time.Now()
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
fmt.Println(ctx.Request().Path(), time.Since(start))
|
|
|
|
}()
|
|
|
|
|
|
|
|
return ctx.Next()
|
|
|
|
})
|
|
|
|
|
2024-03-12 22:31:45 +01:00
|
|
|
s.Run(":8080")
|
2024-03-07 18:09:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
|
|
|
```
|
2024-03-28 12:22:45 +01:00
|
|
|
PASS: TestBytes
|
|
|
|
PASS: TestString
|
|
|
|
PASS: TestError
|
|
|
|
PASS: TestErrorMultiple
|
2024-04-02 16:17:43 +02:00
|
|
|
PASS: TestRedirect
|
2024-03-28 12:22:45 +01:00
|
|
|
PASS: TestRequest
|
|
|
|
PASS: TestRequestHeader
|
|
|
|
PASS: TestRequestParam
|
|
|
|
PASS: TestWrite
|
|
|
|
PASS: TestWriteString
|
|
|
|
PASS: TestResponseCompression
|
|
|
|
PASS: TestResponseHeader
|
|
|
|
PASS: TestResponseHeaderOverwrite
|
2024-03-07 18:09:51 +01:00
|
|
|
PASS: TestPanic
|
2024-03-12 22:32:51 +01:00
|
|
|
PASS: TestRun
|
2024-03-28 14:27:40 +01:00
|
|
|
PASS: TestBadRequest
|
|
|
|
PASS: TestBadRequestHeader
|
|
|
|
PASS: TestBadRequestMethod
|
|
|
|
PASS: TestBadRequestProtocol
|
2025-02-14 22:28:29 +01:00
|
|
|
PASS: TestConnectionClose
|
2024-03-28 14:27:40 +01:00
|
|
|
PASS: TestEarlyClose
|
2024-03-12 22:32:51 +01:00
|
|
|
PASS: TestUnavailablePort
|
2024-03-28 14:27:40 +01:00
|
|
|
coverage: 100.0% of statements
|
2024-03-07 18:09:51 +01:00
|
|
|
```
|
|
|
|
|
|
|
|
## Benchmarks
|
|
|
|
|
2024-03-29 12:59:08 +01:00
|
|
|

|
2024-03-07 18:09:51 +01:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
Please see the [license documentation](https://akyoto.dev/license).
|
|
|
|
|
|
|
|
## Copyright
|
|
|
|
|
2024-03-27 22:12:16 +01:00
|
|
|
© 2024 Eduard Urbach
|