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
|
|
|
|
|
|
|
|
```
|
|
|
|
PASS: TestRouter
|
2024-03-13 19:18:01 +00:00
|
|
|
PASS: TestMiddleware
|
2024-03-07 17:09:51 +00:00
|
|
|
PASS: TestPanic
|
2024-03-12 21:32:51 +00:00
|
|
|
PASS: TestRun
|
|
|
|
PASS: TestUnavailablePort
|
2024-03-07 17:09:51 +00:00
|
|
|
coverage: 100.0% of statements
|
|
|
|
```
|
|
|
|
|
|
|
|
## Benchmarks
|
|
|
|
|
|
|
|
```
|
2024-03-16 14:22:47 +00:00
|
|
|
BenchmarkStatic/#00-12 32963155 30.88 ns/op 0 B/op 0 allocs/op
|
|
|
|
BenchmarkStatic/hello-12 31640433 37.92 ns/op 0 B/op 0 allocs/op
|
|
|
|
BenchmarkStatic/hello/world-12 22497412 52.57 ns/op 0 B/op 0 allocs/op
|
|
|
|
BenchmarkGitHub/gists/:id-12 24162244 49.70 ns/op 0 B/op 0 allocs/op
|
|
|
|
BenchmarkGitHub/repos/:a/:b-12 18865028 59.22 ns/op 0 B/op 0 allocs/op
|
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
|