Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions http/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,31 @@ type serverContext interface {

// Context represents the context for an HTTP request and response.
type Context struct {
req *ServerRequest
res *ServerResponse
endpoint *Endpoint
req *ServerRequest
res *ServerResponse

values map[any]any
err error
}

func NewContext(req *http.Request, writer http.ResponseWriter) *Context {
ctx := &Context{
values: make(map[any]any),
req: &ServerRequest{
nativeReq: req,
},
res: &ServerResponse{
writer: writer,
},
}

ctx.req.ctx = ctx
ctx.res.ctx = ctx

return ctx
}

// Deadline method returns the time when work done on behalf of
// this context should be canceled.
func (c *Context) Deadline() (deadline time.Time, ok bool) {
Expand Down Expand Up @@ -79,6 +97,14 @@ func (c *Context) Response() *ServerResponse {
return c.res
}

func (c *Context) Endpoint() *Endpoint {
return c.endpoint
}

func (c *Context) SetEndpoint(endpoint *Endpoint) {
c.endpoint = endpoint
}

// reset clears the context state and assigns a new HTTP request and response writer.
func (c *Context) reset(w http.ResponseWriter, r *http.Request) {
c.err = nil
Expand Down
8 changes: 4 additions & 4 deletions http/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ import (

// Endpoint represents a fully described HTTP endpoint definition.
type Endpoint struct {
// path is the route pattern associated with this endpoint
// (e.g. "/users/{id}", "/health", "/files/**").
path string

// method is the HTTP method this endpoint responds to
// (e.g. GET, POST, PUT).
method Method

// path is the route pattern associated with this endpoint
// (e.g. "/users/{id}", "/health", "/files/**").
path string

// delegate is the request handler invoked when this endpoint
// matches an incoming request.
delegate RequestDelegate
Expand Down
Loading