run_config.go

Overview

The run_config.go file defines configuration structures and utilities to manage runtime behavior for streaming modes within the system. It primarily encapsulates how streaming communication is configured and propagated through context.Context objects. This enables downstream components to modify behavior based on the specified streaming mode, supporting scenarios like no streaming, server-sent events (SSE), or bidirectional streaming.

Types and Constants

StreamingMode (type)

type StreamingMode string

StreamingMode is a custom string type that enumerates the possible streaming modes supported by the system.

Constants

These constants define the operational mode that components can check to adapt their communication or processing logic accordingly.

RunConfig (struct)

type RunConfig struct {
	StreamingMode StreamingMode
}

RunConfig holds configuration parameters that control runtime execution aspects. Currently, it contains only one field:

This struct can be extended in the future with additional runtime options.

Functions

ToContext

func ToContext(ctx context.Context, cfg *RunConfig) context.Context
cfg := &runconfig.RunConfig{StreamingMode: runconfig.StreamingModeSSE}
ctx := context.Background()
ctxWithConfig := runconfig.ToContext(ctx, cfg)
// ctxWithConfig can now be passed to downstream functions

This function uses an unexported context key to safely store the RunConfig without risk of collision with other context values.

FromContext

func FromContext(ctx context.Context) *RunConfig
cfg := runconfig.FromContext(ctx)
if cfg != nil {
    // Use cfg.StreamingMode or other fields
}

This function performs a type assertion on the stored value to ensure type safety.

Implementation Details

Interaction with Other System Components

Diagram: Structure of run_config.go

classDiagram
class RunConfig {
+StreamingMode: StreamingMode
}
class StreamingMode {
<<enumeration>>
+StreamingModeNone
+StreamingModeSSE
+StreamingModeBidi
}
class ContextFunctions {
+ToContext(ctx, cfg) Context
+FromContext(ctx) *RunConfig
}
RunConfig --> StreamingMode
ContextFunctions ..> RunConfig : uses