diff --git a/Context.go b/Context.go index 2f97aca..946b408 100644 --- a/Context.go +++ b/Context.go @@ -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, + }) } diff --git a/README.md b/README.md index 6128ca4..9193167 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Server.go b/Server.go index edf704b..a285f68 100644 --- a/Server.go +++ b/Server.go @@ -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), } } diff --git a/go.mod b/go.mod index c14016a..1473267 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 3a16cd6..a12e1ec 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/param.go b/param.go deleted file mode 100644 index bbf8d51..0000000 --- a/param.go +++ /dev/null @@ -1,7 +0,0 @@ -package server - -// param represents a URL parameter in a route like `/user/:id`. -type param struct { - Name string - Value string -}