Skip to content

Commit

Permalink
feat: add method NewContext() to return routeContext pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthPestilane committed Nov 12, 2021
1 parent ec323d1 commit 4b8e811
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions router_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import (
"time"
)

// NewContext creates a routeContext pointer.
func NewContext(session Session, request *message.Entry) *routeContext {
return &routeContext{
session: session,
reqEntry: request,
}
}

// Context is a generic context in a message routing.
// It allows us to pass variables between handler and middlewares.
type Context interface {
Expand Down
2 changes: 1 addition & 1 deletion session.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func newSession(conn net.Conn, opt *sessionOption) *session {
respQueue: make(chan Context, opt.respQueueSize),
packer: opt.Packer,
codec: opt.Codec,
ctxPool: sync.Pool{New: func() interface{} { return new(routeContext) }},
ctxPool: sync.Pool{New: func() interface{} { return NewContext(nil, nil) }},
}
}

Expand Down

0 comments on commit 4b8e811

Please sign in to comment.