Added parameter retrieval

This commit is contained in:
2023-07-22 11:48:35 +02:00
parent 968687849f
commit 01f8b2d5be
2 changed files with 24 additions and 5 deletions

View File

@ -14,6 +14,7 @@ const maxParams = 16
type Context interface {
Bytes([]byte) error
Error(status int, messages ...any) error
Get(param string) string
Reader(io.Reader) error
SetStatus(status int)
String(string) error
@ -60,6 +61,17 @@ func (ctx *context) Error(status int, messages ...any) error {
return errors.Join(combined...)
}
// Get retrieves a parameter.
func (ctx *context) Get(param string) string {
for i := 0; i < ctx.paramCount; i++ {
if ctx.paramNames[i] == param {
return ctx.paramValues[i]
}
}
return ""
}
// Reader sends the contents of the io.Reader without creating an in-memory copy.
func (ctx *context) Reader(reader io.Reader) error {
_, err := io.Copy(ctx.response, reader)