Added Status method
This commit is contained in:
12
Context.go
12
Context.go
@ -13,11 +13,12 @@ const maxParams = 16
|
||||
// Context represents the interface for a request & response context.
|
||||
type Context interface {
|
||||
Bytes([]byte) error
|
||||
Error(status int, messages ...any) error
|
||||
Error(messages ...any) error
|
||||
Get(param string) string
|
||||
Reader(io.Reader) error
|
||||
Request() Request
|
||||
Response() Response
|
||||
Status(status int) Context
|
||||
String(string) error
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ func (ctx *ctx) Bytes(body []byte) error {
|
||||
}
|
||||
|
||||
// Error is used for sending error messages to the client.
|
||||
func (ctx *ctx) Error(status int, messages ...any) error {
|
||||
func (ctx *ctx) Error(messages ...any) error {
|
||||
var combined []error
|
||||
|
||||
for _, msg := range messages {
|
||||
@ -58,7 +59,6 @@ func (ctx *ctx) Error(status int, messages ...any) error {
|
||||
}
|
||||
}
|
||||
|
||||
ctx.response.WriteHeader(status)
|
||||
return errors.Join(combined...)
|
||||
}
|
||||
|
||||
@ -89,6 +89,12 @@ func (ctx *ctx) Response() Response {
|
||||
return &ctx.response
|
||||
}
|
||||
|
||||
// Status sets the HTTP status of the response.
|
||||
func (ctx *ctx) Status(status int) Context {
|
||||
ctx.response.WriteHeader(status)
|
||||
return ctx
|
||||
}
|
||||
|
||||
// String responds with the given string.
|
||||
func (ctx *ctx) String(body string) error {
|
||||
slice := unsafe.Slice(unsafe.StringData(body), len(body))
|
||||
|
Reference in New Issue
Block a user