socket

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 11 Imported by: ? 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

Overview

Package socket gives a daemon its Unix socket and a client its connection to it. The file mode is the access control and the user account the trust boundary: the socket's directory is 0700, the socket 0600, both owned by the user, and there are no tokens or TLS.

path := socket.Path(paths.For(id.Name).Runtime, id.Name)
ln, err := socket.Listen(ctx, path) // the daemon; serve it with httpserver's Serve

client := &http.Client{Transport: &http.Transport{
	DialContext: socket.Dialer(path, "myapp service start"),
}}
resp, err := client.Get("http://myapp/v1/drafts") // the host is not used

Listen refuses when another daemon holds or answers on the socket, and removes a socket file only when nobody answers. The dial refuses a socket or directory another user owns. Every refusal is a failure with a next step.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dialer

func Dialer(path, start string) func(ctx context.Context, network, addr string) (net.Conn, error)

Dialer returns an http.Transport DialContext that connects to the socket at path whatever the request's host. It refuses a socket or directory another user owns (permission), a symlink or other file in place of the socket (conflict), and fails as remote with start as the next step when no daemon answers.

func Listen

func Listen(ctx context.Context, path string) (net.Listener, error)

Listen makes the socket at path for a daemon: the directory created 0700 (or set to 0700 when the user owns it), a lock beside the socket held until the listener closes, a stale socket file removed, the socket 0600. Closing the listener removes the socket file.

func Path

func Path(runtimeDir, app string) string

Path is the socket of app in its runtime directory (paths.Paths.Runtime): <runtime>/<app>.sock.

Types

This section is empty.

Jump to

Keyboard shortcuts

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