Documentation
¶
Index ¶
- func BuildURL(base string, params map[string]string) (string, error)
- func DefaultConfigPath() (string, error)
- func Dispatch(cfg *Config, req *CommandRequest) (string, error)
- func ExtractParams(endpoint *EndpointConfig, body string) (map[string]string, error)
- func SendReply(socketPath string, toAddr string, message string) error
- func SplitKV(s string) (string, string)
- type CommandRequest
- type Config
- type EndpointConfig
- type InboxMessage
- type UnknownCommandError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultConfigPath ¶
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:
- Look up command in config.
- Match body against arg_regex; extract named capture groups as query params.
- Build the service URL and issue an HTTP GET.
- 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 ¶
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 ¶
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 ¶
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 ¶
LoadConfig loads and validates endpoints.yaml from the default path.
func LoadConfigFrom ¶
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 ¶
ParseEndpointsYAML parses the specific endpoints.yaml structure without external deps.
Expected format:
commands:
- name: <string>
link: <url>
arg_regex: <regex> # optional
func (*Config) CommandList ¶
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 ¶
UnknownCommandError is returned when the requested command is not in the config.
func (*UnknownCommandError) Error ¶
func (e *UnknownCommandError) Error() string