cmdjsonl

package
v1.17.1 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type InvalidHandler

type InvalidHandler struct {
	Cmd    string // The command for which the handler is invalid.
	Reason string // The reason why the handler is invalid.
}

func (*InvalidHandler) Error

func (e *InvalidHandler) Error() string

type ParseError

type ParseError struct {
	Line int
	When string
	Msg  string
}

ParseError represents an error that occurred during parsing of the input. It includes the line number where the error occurred, a description of when the error happened, and a message describing the error itself.

func (*ParseError) Error

func (p *ParseError) Error() string

type Parser

type Parser struct {
	// contains filtered or unexported fields
}

Parser parses input data in the cmdjsonl format (MIME type: application/x-cmdjsonl) and dispatches commands to registered handlers. Each line of input is expected to contain a command followed by a JSON object, separated by a space. The parser reads the input line by line, extracts the command and the JSON object, and invokes the corresponding handler.

func (*Parser) HandleFunc

func (p *Parser) HandleFunc(cmd string, fn any) error

HandleFunc registers a handler function for a specific command. The handler function must have exactly one parameter, which can be either a pointer or a non-pointer type. The function can optionally return an error. If the handler function does not meet these requirements, an InvalidHandler error is returned.

func (*Parser) Parse

func (p *Parser) Parse(in io.Reader, maxLine int) error

Parse reads from the provided io.Reader line by line, expecting each line to contain a command followed by a JSON object. It uses the registered handlers to process each command. If any error occurs during reading, parsing, or handling a command, a ParseError is returned with details about the error.

Jump to

Keyboard shortcuts

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