2024-03-22 14:08:24 +00:00
|
|
|
# web
|
2023-07-18 11:37:05 +00:00
|
|
|
|
2024-03-22 14:08:24 +00:00
|
|
|
Web server.
|
2023-07-18 19:48:38 +00:00
|
|
|
|
2024-03-07 17:09:51 +00:00
|
|
|
## Features
|
|
|
|
|
2024-03-15 09:06:17 +00:00
|
|
|
- High performance
|
2024-03-07 17:17:01 +00:00
|
|
|
- Low latency
|
|
|
|
- Radix tree routing
|
2024-03-07 17:09:51 +00:00
|
|
|
|
2023-07-18 19:48:38 +00:00
|
|
|
## Installation
|
|
|
|
|
|
|
|
```shell
|
2024-03-22 14:08:24 +00:00
|
|
|
go get git.akyoto.dev/go/web
|
2023-07-18 19:48:38 +00:00
|
|
|
```
|
|
|
|
|
2024-03-07 17:09:51 +00:00
|
|
|
## Usage
|
2023-07-18 19:48:38 +00:00
|
|
|
|
|
|
|
```go
|
2024-03-22 14:08:24 +00:00
|
|
|
s := web.NewServer()
|
2023-07-18 19:48:38 +00:00
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Static route
|
2024-03-22 14:08:24 +00:00
|
|
|
s.Get("/", func(ctx web.Context) error {
|
2023-07-18 19:48:38 +00:00
|
|
|
return ctx.String("Hello")
|
|
|
|
})
|
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Parameter route
|
2024-03-22 14:08:24 +00:00
|
|
|
s.Get("/blog/:post", func(ctx web.Context) error {
|
2023-07-22 09:54:13 +00:00
|
|
|
return ctx.String(ctx.Get("post"))
|
|
|
|
})
|
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Wildcard route
|
2024-03-22 14:08:24 +00:00
|
|
|
s.Get("/images/*file", func(ctx web.Context) error {
|
2023-07-22 09:54:13 +00:00
|
|
|
return ctx.String(ctx.Get("file"))
|
|
|
|
})
|
2024-03-07 17:17:01 +00:00
|
|
|
|
2024-03-12 21:31:45 +00:00
|
|
|
s.Run(":8080")
|
2024-03-07 17:09:51 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
|
|
|
```
|
2024-03-28 11:22:45 +00:00
|
|
|
PASS: TestBytes
|
|
|
|
PASS: TestString
|
|
|
|
PASS: TestError
|
|
|
|
PASS: TestErrorMultiple
|
|
|
|
PASS: TestRequest
|
|
|
|
PASS: TestRequestHeader
|
|
|
|
PASS: TestRequestParam
|
|
|
|
PASS: TestWrite
|
|
|
|
PASS: TestWriteString
|
|
|
|
PASS: TestResponseCompression
|
|
|
|
PASS: TestResponseHeader
|
|
|
|
PASS: TestResponseHeaderOverwrite
|
2024-03-07 17:09:51 +00:00
|
|
|
PASS: TestPanic
|
2024-03-12 21:32:51 +00:00
|
|
|
PASS: TestRun
|
2024-03-28 13:27:40 +00:00
|
|
|
PASS: TestBadRequest
|
|
|
|
PASS: TestBadRequestHeader
|
|
|
|
PASS: TestBadRequestMethod
|
|
|
|
PASS: TestBadRequestProtocol
|
|
|
|
PASS: TestEarlyClose
|
2024-03-12 21:32:51 +00:00
|
|
|
PASS: TestUnavailablePort
|
2024-03-28 13:27:40 +00:00
|
|
|
coverage: 100.0% of statements
|
2024-03-07 17:09:51 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Benchmarks
|
|
|
|
|
2024-03-28 20:41:11 +00:00
|
|
|
![wrk: requests per second](https://i.imgur.com/PBPH845.png)
|
2024-03-07 17:09:51 +00:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
Please see the [license documentation](https://akyoto.dev/license).
|
|
|
|
|
|
|
|
## Copyright
|
|
|
|
|
2024-03-27 21:12:16 +00:00
|
|
|
© 2024 Eduard Urbach
|