ipc

package
v1.6.3-0...-5d87a77 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const PendingTopic = "ui"

PendingTopic is the topic PendingOpen publishes on.

Variables

This section is empty.

Functions

func FindRunningSocket

func FindRunningSocket(appName string) (string, error)

func FindRunningSocketAny

func FindRunningSocketAny(appNames ...string) (string, error)

Types

type Capabilities

type Capabilities struct {
	APIVersion   int      `json:"apiVersion"`
	Capabilities []string `json:"capabilities"`
}

type Client

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

func Dial

func Dial(socketPath string) (*Client, error)

func (*Client) Call

func (c *Client) Call(req Request) (*Response[any], error)

func (*Client) Close

func (c *Client) Close() error

type Config

type Config struct {
	AppName                string
	APIVersion             int
	Capabilities           []string
	CapabilitiesFunc       func() []string // computed per connection; overrides Capabilities when set
	MaxLineSize            int
	DefaultSubscribeTopics []string
	OnSubscribe            func(topics []string, sub *Subscriber)
	SubscribeHandler       Handler // replaces the built-in subscribe/unsubscribe handling when set
	Bus                    *EventBus
}

type ConnWriter

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

func NewConnWriter

func NewConnWriter(conn net.Conn) *ConnWriter

func (*ConnWriter) Respond

func (w *ConnWriter) Respond[T any](id int, result T)

func (*ConnWriter) RespondError

func (w *ConnWriter) RespondError(id int, msg string)

func (*ConnWriter) WriteEvent

func (w *ConnWriter) WriteEvent(ev Event) error

func (*ConnWriter) WriteResponse

func (w *ConnWriter) WriteResponse(resp any) error

type Event

type Event struct {
	Topic string
	Data  any
}

type EventBus

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

func NewEventBus

func NewEventBus() *EventBus

func (*EventBus) HasSubscriber

func (b *EventBus) HasSubscriber(topic string) bool

func (*EventBus) NewSubscriber

func (b *EventBus) NewSubscriber(ctx context.Context, writer *ConnWriter) *Subscriber

func (*EventBus) Publish

func (b *EventBus) Publish(topic string, data any)

type Handler

type Handler func(ctx context.Context, w *ConnWriter, req Request, sub *Subscriber)

type Mux

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

func NewMux

func NewMux() *Mux

func (*Mux) Handle

func (m *Mux) Handle(method string, h Handler)

func (*Mux) HandlePrefix

func (m *Mux) HandlePrefix(prefix string, h Handler)

func (*Mux) ServeIPC

func (m *Mux) ServeIPC(ctx context.Context, w *ConnWriter, req Request, sub *Subscriber)

type PendingOpen

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

PendingOpen holds "ui" actions that arrived before the UI subscribed, so a cold start still honors them.

func (*PendingOpen) Deliver

func (p *PendingOpen) Deliver(bus *EventBus, payload map[string]any)

Deliver publishes payload now when the UI listens and nothing is queued ahead of it, otherwise queues it.

func (*PendingOpen) Flush

func (p *PendingOpen) Flush(bus *EventBus)

Flush publishes everything queued, in order.

func (*PendingOpen) Take

func (p *PendingOpen) Take() []map[string]any

Take empties the queue and returns what it held, for a caller that answers with it instead of publishing.

type Request

type Request struct {
	ID     int            `json:"id,omitempty"`
	Method string         `json:"method"`
	Params map[string]any `json:"params,omitempty"`
}

func (Request) Get

func (r Request) Get[T any](key string) (T, bool)

func (Request) GetOr

func (r Request) GetOr[T any](key string, def T) T

type Response

type Response[T any] struct {
	ID     int    `json:"id,omitempty"`
	Result *T     `json:"result,omitempty"`
	Error  string `json:"error,omitempty"`
}

type Server

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

func NewServer

func NewServer(cfg Config, handler Handler) *Server

func (*Server) Bus

func (s *Server) Bus() *EventBus

func (*Server) Close

func (s *Server) Close() error

func (*Server) Listen

func (s *Server) Listen() error

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

func (*Server) Serve

func (s *Server) Serve(ctx context.Context) error

func (*Server) Shutdown

func (s *Server) Shutdown(context.Context) error

func (*Server) SocketPath

func (s *Server) SocketPath() string

type Subscriber

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

func (*Subscriber) Close

func (s *Subscriber) Close()

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(topics ...string)

func (*Subscriber) Topics

func (s *Subscriber) Topics() []string

func (*Subscriber) Unsubscribe

func (s *Subscriber) Unsubscribe(topics ...string)

Directories

Path Synopsis
Package spec describes an app's IPC methods for `describe`, `ipc list` and shell completion, and parses the `ipc <method> key=value...` command line into request params.
Package spec describes an app's IPC methods for `describe`, `ipc list` and shell completion, and parses the `ipc <method> key=value...` command line into request params.

Jump to

Keyboard shortcuts

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