diff --git a/templates/constants.templ b/templates/constants.templ index f5e9277..40a6350 100644 --- a/templates/constants.templ +++ b/templates/constants.templ @@ -1,5 +1,6 @@ {{define "constants"}} const ConnectionContextKey int = 1000 + const StreamContextKey int = 1001 func SetErrorFlag(flags uint8, error bool) uint8 { return flags | 0x2 diff --git a/templates/server.templ b/templates/server.templ index 42f245c..810edc9 100644 --- a/templates/server.templ +++ b/templates/server.templ @@ -54,6 +54,8 @@ func NewServer({{ GetServerFields .services }}, tlsConfig *tls.Config, logger ty {{ if .numStreamMethods -}} s.server.SetStreamHandler(func(ctx context.Context, stream *frisbee.Stream) { + streamCtx := context.WithValue(ctx, ConnectionContextKey, stream.Conn()) + streamCtx = context.WithValue(streamCtx, StreamContextKey, stream) p, err := stream.ReadPacket() if err != nil { return @@ -73,7 +75,7 @@ func NewServer({{ GetServerFields .services }}, tlsConfig *tls.Config, logger ty {{ $opIndex := call $counter -}} {{ if or $method.IsStreamingClient $method.IsStreamingServer -}} case {{ $opIndex }}: - s.create{{ CamelCaseName $method.Name }}Server(ctx, {{ FirstLowerCase (CamelCaseName $service.Name) }}, stream) + s.create{{ CamelCaseName $method.Name }}Server(streamCtx, {{ FirstLowerCase (CamelCaseName $service.Name) }}, stream) {{end -}} {{end -}} {{end -}}