responder

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildURL

func BuildURL(base string, params map[string]string) (string, error)

BuildURL appends params as query string values to base.

func DefaultConfigPath

func DefaultConfigPath() (string, error)

DefaultConfigPath returns ~/.pilot/endpoints.yaml.

func Dispatch

func Dispatch(cfg *Config, req *CommandRequest) (string, error)

Dispatch validates a CommandRequest against cfg, calls the backing service, and returns the response body.

The full cycle is:

  1. Look up command in config.
  2. Match body against arg_regex; extract named capture groups as query params.
  3. Build the service URL and issue an HTTP GET.
  4. Return the response body on 2xx, or an error otherwise.

func ExtractParams

func ExtractParams(endpoint *EndpointConfig, body string) (map[string]string, error)

ExtractParams applies the endpoint's arg_regex to body and returns a map of named capture groups → values that will be appended as query parameters.

If the endpoint has no arg_regex, no query params are added (bare link is used). Returns an error when a regex is configured but the body does not match.

func SendReply

func SendReply(socketPath string, toAddr string, message string) error

SendReply sends a plain-text message back to toAddr via the local pilot daemon. It dials the remote node's data-exchange port (1001), sends a TypeText frame, and waits for the ACK before closing to ensure delivery.

func SplitKV

func SplitKV(s string) (string, string)

SplitKV splits "key: value" into ("key", "value"), handling YAML quoting. Double-quoted values: processes \\ → \ and \" → " escape sequences (YAML spec). Single-quoted values: content is verbatim (no escapes in YAML single-quoted strings). Unquoted values: trailing inline comments (` #...`) are stripped.

Types

type CommandRequest

type CommandRequest struct {
	Command string `json:"command"`
	Body    string `json:"body"`
}

CommandRequest is the JSON payload expected in InboxMessage.Data. Senders must format their message as: {"command":"<name>","body":"<args>"}

type Config

type Config struct {
	Commands []EndpointConfig
}

Config holds all endpoint configurations loaded from endpoints.yaml.

func LoadConfig

func LoadConfig() (*Config, error)

LoadConfig loads and validates endpoints.yaml from the default path.

func LoadConfigFrom

func LoadConfigFrom(path string) (*Config, error)

LoadConfigFrom loads and validates endpoints.yaml from a specific path. Returns an error (and exits-worthy message) if the file is missing, malformed, or contains no commands — responder cannot start without a valid config.

func ParseEndpointsYAML

func ParseEndpointsYAML(r io.Reader) (*Config, error)

ParseEndpointsYAML parses the specific endpoints.yaml structure without external deps.

Expected format:

commands:
  - name: <string>
    link: <url>
    arg_regex: <regex>   # optional

func (*Config) CommandList

func (c *Config) CommandList() string

CommandList returns a human-readable listing of all available commands.

func (*Config) EndpointByName

func (c *Config) EndpointByName(name string) (*EndpointConfig, bool)

EndpointByName looks up a command by name.

type EndpointConfig

type EndpointConfig struct {
	Name     string
	Link     string
	ArgRegex string
	// contains filtered or unexported fields
}

EndpointConfig represents a single command endpoint loaded from endpoints.yaml.

func (*EndpointConfig) Compile

func (e *EndpointConfig) Compile() error

Compile compiles ArgRegex and stores it on the endpoint. Called automatically by LoadConfigFrom; exposed so tests can build EndpointConfig values directly without going through a YAML file.

func (*EndpointConfig) Compiled

func (e *EndpointConfig) Compiled() *regexp.Regexp

Compiled returns the compiled arg_regex, or nil if none was specified.

type InboxMessage

type InboxMessage struct {
	Type       string `json:"type"`
	From       string `json:"from"`
	Data       string `json:"data"`
	Bytes      int    `json:"bytes"`
	ReceivedAt string `json:"received_at"`
	// contains filtered or unexported fields
}

InboxMessage represents a message stored on disk by the pilot daemon at ~/.pilot/inbox/<TYPE>-<TIMESTAMP>.json.

func ReadInbox

func ReadInbox() ([]*InboxMessage, error)

ReadInbox reads all JSON message files from ~/.pilot/inbox/. Files that cannot be read or parsed are silently skipped. Returns nil, nil when the inbox directory does not exist yet.

func ReadInboxFrom

func ReadInboxFrom(dir string) ([]*InboxMessage, error)

ReadInboxFrom reads all JSON message files from the given directory. Files that cannot be read or parsed are silently skipped. Returns nil, nil when the directory does not exist.

func (*InboxMessage) Delete

func (m *InboxMessage) Delete() error

Delete removes the inbox message file from disk.

func (*InboxMessage) ParseRequest

func (m *InboxMessage) ParseRequest() (*CommandRequest, error)

ParseRequest unmarshals the Data field into a CommandRequest.

type UnknownCommandError

type UnknownCommandError struct {
	Command   string
	Available string
}

UnknownCommandError is returned when the requested command is not in the config.

func (*UnknownCommandError) Error

func (e *UnknownCommandError) Error() string

Jump to

Keyboard shortcuts

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