ssecodegen

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 12, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitHeadersBody

func InitHeadersBody(writerExpr string, opts HeaderOptions) []jen.Code

InitHeadersBody returns Jennifer statements that initialize SSE response headers for the given writer expression.

func InitHeadersSource

func InitHeadersSource(writerExpr string, opts HeaderOptions) string

InitHeadersSource renders source code that initializes SSE response headers for the given writer expression.

func WriteAndFlushBody

func WriteAndFlushBody(writeCall jen.Code, writerExpr string, opts ...ObserveOption) []jen.Code

WriteAndFlushBody returns Jennifer statements that write an SSE event using the provided call and then flush the response controller for the writer.

When ObserveOption.CtxExpr is provided, the emitted observer references use the `loomtransport` alias so the generated code shares the import registered in the surrounding server file header. We deliberately avoid jen.Qual on observability/transport here to keep TestGeneratorFilesDoNotMixNamedLoomImportsWithJenQual passing.

func WriteAndFlushSource

func WriteAndFlushSource(writeCall string, writerExpr string, opts ...ObserveOption) string

WriteAndFlushSource renders source that writes an SSE event with the given call expression and flushes the response controller. When opts.CtxExpr is non-empty the generated code also reports stream write and flush failures through loomtransport.Observe before returning the error.

Types

type HeaderOptions

type HeaderOptions struct {
	// PreserveExisting keeps caller-supplied header values when they are set.
	PreserveExisting bool
	// IncludeAccelBuffering emits X-Accel-Buffering: no for proxy buffering control.
	IncludeAccelBuffering bool
}

HeaderOptions controls how generated SSE header initialization behaves.

type ObserveOption added in v1.0.13

type ObserveOption struct {
	// CtxExpr is the in-scope expression that yields the request context.
	CtxExpr string
	// Transport is the loomtransport.TransportKind constant identifier
	// (e.g. "loomtransport.TransportHTTP") that classifies emitted events.
	// When empty, "loomtransport.TransportHTTP" is used.
	Transport string
}

ObserveOption configures generated observer emissions for SSE write and flush failures. When CtxExpr is set to an in-scope Go expression that yields a context.Context (typically "ctx"), the generated code emits stream-failure events via loomtransport.Observe; leaving it empty keeps the legacy bare write+flush code shape.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL