Updated dependencies

This commit is contained in:
Eduard Urbach 2024-03-15 10:06:17 +01:00
parent 8f135c1dcd
commit 4faeb6e956
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0
6 changed files with 19 additions and 20 deletions

View File

@ -5,6 +5,8 @@ import (
"io"
"net/http"
"unsafe"
"git.akyoto.dev/go/router"
)
// Context represents the interface for a request & response context.
@ -33,7 +35,7 @@ type ctx struct {
request *http.Request
response http.ResponseWriter
server *server
params []param
params []router.Parameter
handlerCount uint8
}
@ -64,7 +66,7 @@ func (ctx *ctx) Get(param string) string {
for i := range len(ctx.params) {
p := ctx.params[i]
if p.Name == param {
if p.Key == param {
return p.Value
}
}
@ -147,6 +149,9 @@ func (ctx *ctx) WriteString(body string) (int, error) {
}
// addParameter adds a new parameter to the context.
func (ctx *ctx) addParameter(name string, value string) {
ctx.params = append(ctx.params, param{name, value})
func (ctx *ctx) addParameter(key string, value string) {
ctx.params = append(ctx.params, router.Parameter{
Key: key,
Value: value,
})
}

View File

@ -4,6 +4,7 @@ HTTP server.
## Features
- High performance
- Low latency
- Radix tree routing
@ -50,11 +51,11 @@ coverage: 100.0% of statements
## Benchmarks
```
BenchmarkStatic/#00-12 36761953 31.12 ns/op 0 B/op 0 allocs/op
BenchmarkStatic/hello-12 28145253 41.21 ns/op 0 B/op 0 allocs/op
BenchmarkStatic/hello/world-12 21206058 55.10 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/gists/:id-12 21452644 52.65 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/repos/:a/:b-12 17888092 61.59 ns/op 0 B/op 0 allocs/op
BenchmarkStatic/#00-12 34907296 30.19 ns/op 0 B/op 0 allocs/op
BenchmarkStatic/hello-12 27628322 40.89 ns/op 0 B/op 0 allocs/op
BenchmarkStatic/hello/world-12 21330940 56.24 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/gists/:id-12 23608254 50.86 ns/op 0 B/op 0 allocs/op
BenchmarkGitHub/repos/:a/:b-12 18912602 59.02 ns/op 0 B/op 0 allocs/op
```
## License

View File

@ -62,7 +62,7 @@ func New() Server {
s.pool.New = func() any {
return &ctx{
server: s,
params: make([]param, 0, 8),
params: make([]router.Parameter, 0, 8),
}
}

2
go.mod
View File

@ -4,5 +4,5 @@ go 1.22
require (
git.akyoto.dev/go/assert v0.1.3
git.akyoto.dev/go/router v0.1.3
git.akyoto.dev/go/router v0.1.4
)

4
go.sum
View File

@ -1,4 +1,4 @@
git.akyoto.dev/go/assert v0.1.3 h1:QwCUbmG4aZYsNk/OuRBz1zWVKmGlDUHhOnnDBfn8Qw8=
git.akyoto.dev/go/assert v0.1.3/go.mod h1:0GzMaM0eURuDwtGkJJkCsI7r2aUKr+5GmWNTFPgDocM=
git.akyoto.dev/go/router v0.1.3 h1:H4wJCYdDD3/i9miYSK/e5sCoGiXe9OX7KmgH4/Toa60=
git.akyoto.dev/go/router v0.1.3/go.mod h1:VfSsK/Z6fUhT3pWaAAnuAcj++bWRZD+bzNaqJoTAunU=
git.akyoto.dev/go/router v0.1.4 h1:ZL5HPl4aNn4QKihf3VVs0Mm9R6ZGn2StAHGRQxjEbws=
git.akyoto.dev/go/router v0.1.4/go.mod h1:rbHbkLJlQOafuOuvBalO3O8E0JtMFPT3zzTKX3h9T08=

View File

@ -1,7 +0,0 @@
package server
// param represents a URL parameter in a route like `/user/:id`.
type param struct {
Name string
Value string
}