2023-07-18 19:48:38 +00:00
|
|
|
# server
|
2023-07-18 11:37:05 +00:00
|
|
|
|
2023-07-18 19:48:38 +00:00
|
|
|
HTTP server.
|
|
|
|
|
2024-03-07 17:09:51 +00:00
|
|
|
## Features
|
|
|
|
|
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
|
|
|
|
go get git.akyoto.dev/go/server
|
|
|
|
```
|
|
|
|
|
2024-03-07 17:09:51 +00:00
|
|
|
## Usage
|
2023-07-18 19:48:38 +00:00
|
|
|
|
|
|
|
```go
|
|
|
|
s := server.New()
|
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Static route
|
2023-07-18 19:48:38 +00:00
|
|
|
s.Get("/", func(ctx server.Context) error {
|
|
|
|
return ctx.String("Hello")
|
|
|
|
})
|
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Parameter route
|
2023-07-22 09:54:13 +00:00
|
|
|
s.Get("/blog/:post", func(ctx server.Context) error {
|
|
|
|
return ctx.String(ctx.Get("post"))
|
|
|
|
})
|
|
|
|
|
2024-03-07 17:17:01 +00:00
|
|
|
// Wildcard route
|
2023-07-22 09:54:13 +00:00
|
|
|
s.Get("/images/*file", func(ctx server.Context) error {
|
|
|
|
return ctx.String(ctx.Get("file"))
|
|
|
|
})
|
2024-03-07 17:17:01 +00:00
|
|
|
|
|
|
|
http.ListenAndServe(":8080", s)
|
2024-03-07 17:09:51 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## Tests
|
|
|
|
|
|
|
|
```
|
|
|
|
PASS: TestRouter
|
|
|
|
PASS: TestPanic
|
|
|
|
coverage: 100.0% of statements
|
|
|
|
```
|
|
|
|
|
|
|
|
## Benchmarks
|
|
|
|
|
|
|
|
```
|
2024-03-12 19:35:19 +00:00
|
|
|
BenchmarkHello-12 33502272 33.64 ns/op 0 B/op 0 allocs/op
|
|
|
|
BenchmarkGitHub-12 17698947 65.50 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
|
|
|
|
|
|
|
|
© 2023 Eduard Urbach
|