Skip to content

Commit

Permalink
ctxConnId shouldn't be exported to avoid collisions
Browse files Browse the repository at this point in the history
  • Loading branch information
wneessen committed Oct 6, 2021
1 parent bbbc170 commit b1610a0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pps.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const DefaultPort = "10005"
type CtxKey int

const (
// CtxConnId represents the connection id in the connection context
CtxConnId CtxKey = iota
// ctxConnId represents the connection id in the connection context
ctxConnId CtxKey = iota

// CtxNoLog lets the user control wether the server should log to
// STDERR or not
Expand Down Expand Up @@ -273,7 +273,7 @@ func (s *Server) Run(ctx context.Context, h Handler) error {
}

connId := xid.New()
conCtx := context.WithValue(ctx, CtxConnId, connId)
conCtx := context.WithValue(ctx, ctxConnId, connId)
go connHandler(conCtx, conn)
}

Expand All @@ -283,7 +283,7 @@ func (s *Server) Run(ctx context.Context, h Handler) error {
// connHandler processes the incoming policy connection request and hands it to the
// Handle function of the Handler interface
func connHandler(ctx context.Context, c *Connection) {
connId, ok := ctx.Value(CtxConnId).(xid.ID)
connId, ok := ctx.Value(ctxConnId).(xid.ID)
if !ok {
log.Print("failed to retrieve connection id from context.")
return
Expand Down

0 comments on commit b1610a0

Please sign in to comment.