ipc

package
v0.0.0-...-3bed8bd Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIPCTimeout        = errors.New("ipc request timeout")
	ErrUnknownCommand    = Error{"unknown-command", "Unknown command"}
	ErrSizeLimitExceeded = Error{Code: "size_limit_exceeded"}
	ErrTimeoutError      = Error{Code: "timeout"}
	ErrUnsupportedError  = Error{Code: "unsupported"}
	ErrNotFound          = Error{Code: "not_found"}
)

Functions

This section is empty.

Types

type Command

type Command string
const (
	CommandResponse Command = "response"
	CommandError    Command = "error"
	CommandLog      Command = "log"
)

type Error

type Error struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

func (Error) Error

func (err Error) Error() string

func (Error) Is

func (err Error) Is(other error) bool

type HandlerFunc

type HandlerFunc func(ctx context.Context, message json.RawMessage) any

func NoDataHandler

func NoDataHandler(fn func(ctx context.Context) any) HandlerFunc

func TypedHandler

func TypedHandler[T any](fn func(ctx context.Context, req T) any) HandlerFunc

type LockedWriter

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

func NewLockedWriter

func NewLockedWriter(wr io.Writer) *LockedWriter

func (*LockedWriter) Encode

func (ls *LockedWriter) Encode(msg any) error

func (*LockedWriter) Write

func (ls *LockedWriter) Write(data []byte) (int, error)

func (*LockedWriter) WriteLevel

func (ls *LockedWriter) WriteLevel(_ zerolog.Level, msg []byte) (n int, err error)

type Message

type Message struct {
	Command    Command         `json:"command"`
	ResponseTo Command         `json:"response_to,omitempty"`
	ID         int             `json:"id,omitempty"`
	Data       json.RawMessage `json:"data,omitempty"`
}

type OutgoingMessage

type OutgoingMessage struct {
	Command    Command `json:"command"`
	ResponseTo Command `json:"response_to,omitempty"`
	ID         int     `json:"id,omitempty"`
	Data       any     `json:"data,omitempty"`
}

type Processor

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

func NewProcessor

func NewProcessor(lw *LockedWriter, input io.Reader, logger *zerolog.Logger) *Processor

func (*Processor) Loop

func (ipc *Processor) Loop()

func (*Processor) Request

func (ipc *Processor) Request(ctx context.Context, cmd Command, reqData any, respData any) error

func (*Processor) RequestAsync

func (ipc *Processor) RequestAsync(cmd Command, data any) (<-chan *Message, int, error)

func (*Processor) Send

func (ipc *Processor) Send(cmd Command, data any) error

func (*Processor) SetHandler

func (ipc *Processor) SetHandler(command Command, handler HandlerFunc)

Jump to

Keyboard shortcuts

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