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 ¶
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 ¶
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 ¶
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.