...

Source file src/github.com/99designs/gqlgen/graphql/handler/transport/websocket_close_reason.go

Documentation: github.com/99designs/gqlgen/graphql/handler/transport

     1  package transport
     2  
     3  import (
     4  	"context"
     5  )
     6  
     7  // A private key for context that only this package can access. This is important
     8  // to prevent collisions between different context uses
     9  var closeReasonCtxKey = &wsCloseReasonContextKey{"close-reason"}
    10  
    11  type wsCloseReasonContextKey struct {
    12  	name string
    13  }
    14  
    15  func AppendCloseReason(ctx context.Context, reason string) context.Context {
    16  	return context.WithValue(ctx, closeReasonCtxKey, reason)
    17  }
    18  
    19  func closeReasonForContext(ctx context.Context) string {
    20  	reason, _ := ctx.Value(closeReasonCtxKey).(string)
    21  	return reason
    22  }
    23  

View as plain text