Documentation
¶
Overview ¶
Package ctl is the local control protocol between the lfr CLI and the running server: one JSON request per connection over a unix socket that only the server's user (and group) can open. There is no network API.
Index ¶
- Constants
- Variables
- func Listen(path string, mode os.FileMode) (net.Listener, error)
- func Proxy(ctx context.Context, path string, in io.Reader, out io.Writer) error
- func SSH(target, remoteData string) func(ctx context.Context) (net.Conn, error)
- type Client
- type Error
- type Handler
- type Request
- type Response
- type Server
- type StreamHandler
Constants ¶
View Source
const ( CodeNotFound = "not_found" CodeInvalid = "invalid" CodeConflict = "conflict" CodeInternal = "internal" )
Codes.
Variables ¶
View Source
var ErrNotRunning = errors.New("lfr server is not running")
ErrNotRunning means nothing listens on the socket.
Functions ¶
func Proxy ¶
Proxy copies between in/out and the control socket at path until either side closes: the remote end of SSH.
Types ¶
type Client ¶
type Client struct {
Path string
Timeout time.Duration
// Dial replaces the unix socket, e.g. with a pipe through ssh.
Dial func(ctx context.Context) (net.Conn, error)
}
Client calls a server.
type Request ¶
type Request struct {
Op string `json:"op"`
Args json.RawMessage `json:"args,omitempty"`
}
Request is one call.
type Response ¶
type Response struct {
OK bool `json:"ok"`
Data json.RawMessage `json:"data,omitempty"`
Error string `json:"error,omitempty"`
Code string `json:"code,omitempty"` // not_found, invalid, conflict, internal
Done bool `json:"done,omitempty"`
}
Response is the answer; streams send several Data lines, then a final one with Done.
type Server ¶
type Server struct {
Log *slog.Logger
Classify func(error) string // maps errors to codes
// contains filtered or unexported fields
}
Server dispatches calls.
func (*Server) Stream ¶
func (s *Server) Stream(op string, h StreamHandler)
Stream registers a streaming operation.
type StreamHandler ¶
StreamHandler sends values until ctx ends or it returns.
Click to show internal directories.
Click to hide internal directories.