Documentation
¶
Overview ¶
Package network provides domain types and autocompletion predictors for network interfaces, hosts, ports, HTTP status codes, MIME types, and HTTP methods, plus an optional standard library binding for *net.Interface fields.
Every exported domain type implements encoding.TextUnmarshaler and Predict: fields declared with these types coerce automatically and complete from package tables or live system state. Invalid values classify under conga.ErrCoerce with the flag and reason named in the message. Host.LookupIP and NetInterface.Interface report a blank receiver as an error naming the failed lookup.
Mount RegisterInterface to register *net.Interface with net.InterfaceByName and enable interface completion on fields typed with the standard library type:
type CLI struct {
Iface conga.OptionalFlag[network.NetInterface] `short:"i" help:"Network interface"`
Peer conga.OptionalFlag[*net.Interface] `short:"p" help:"Peer interface"`
}
app := conga.New[CLI]().Use(network.RegisterInterface)
See https://docs.conga.sh/reference/domain-types/ for the domain type reference.
Index ¶
- func HTTPMethods() predict.Predictor
- func HTTPStatusCodes() predict.Predictor
- func Hosts() predict.Predictor
- func MIMETypes() predict.Predictor
- func NetInterfaces() predict.Predictor
- func Ports() predict.Predictor
- func RegisterInterface[T any](app *conga.App[T])
- func RegisterNetInterface[T any](app *conga.App[T])
- type HTTPMethod
- type HTTPStatus
- func (s HTTPStatus) Code() int
- func (s HTTPStatus) Help() string
- func (s HTTPStatus) IsClientError() bool
- func (s HTTPStatus) IsServerError() bool
- func (s HTTPStatus) IsSuccess() bool
- func (s HTTPStatus) MarshalText() ([]byte, error)
- func (s HTTPStatus) Predict() predict.Predictor
- func (s HTTPStatus) String() string
- func (s HTTPStatus) Text() string
- func (s *HTTPStatus) UnmarshalText(text []byte) error
- type Host
- type MIMEType
- type NetInterface
- func (n NetInterface) Addrs() ([]net.Addr, error)
- func (n NetInterface) Help() string
- func (n NetInterface) Interface() (*net.Interface, error)
- func (n NetInterface) MarshalText() ([]byte, error)
- func (n NetInterface) Predict() predict.Predictor
- func (n NetInterface) String() string
- func (n *NetInterface) UnmarshalText(text []byte) error
- type Port
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HTTPMethods ¶
HTTPMethods configures completion of standard HTTP request methods (GET, POST, PUT, DELETE, etc.).
func HTTPStatusCodes ¶
HTTPStatusCodes configures completion of standard HTTP status codes with human-readable descriptions.
func Hosts ¶
Hosts configures completion of hostnames from /etc/hosts, SSH known_hosts, and SSH config.
func NetInterfaces ¶
NetInterfaces configures completion of network interface names discovered on the system.
func Ports ¶
Ports configures completion of well-known TCP/UDP service ports with descriptive annotations.
func RegisterInterface ¶
RegisterInterface mounts *net.Interface support onto the app builder: the parser resolves interface names (e.g. lo, eth0) with net.InterfaceByName and completion offers the host's interfaces. Apply with app.Use.
func RegisterNetInterface ¶
RegisterNetInterface mounts *net.Interface support onto the app builder, aliasing RegisterInterface. Apply with app.Use.
Types ¶
type HTTPMethod ¶
type HTTPMethod string
HTTPMethod represents a standard HTTP request verb (GET, POST, PUT, DELETE, etc.).
func (HTTPMethod) Help ¶
func (m HTTPMethod) Help() string
Help returns the default value syntax description for HTTP method flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (HTTPMethod) MarshalText ¶
func (m HTTPMethod) MarshalText() ([]byte, error)
MarshalText encodes the HTTP method into UTF-8 text bytes.
func (HTTPMethod) Predict ¶
func (m HTTPMethod) Predict() predict.Predictor
Predict returns HTTP method autocompletion candidates.
func (HTTPMethod) String ¶
func (m HTTPMethod) String() string
String returns the HTTP method in uppercase.
func (*HTTPMethod) UnmarshalText ¶
func (m *HTTPMethod) UnmarshalText(text []byte) error
UnmarshalText parses and validates a standard HTTP method verb.
type HTTPStatus ¶
type HTTPStatus int
HTTPStatus represents an HTTP response status code (100–599).
func (HTTPStatus) Code ¶
func (s HTTPStatus) Code() int
Code returns the HTTP status code as an integer.
func (HTTPStatus) Help ¶
func (s HTTPStatus) Help() string
Help returns the default value syntax description for HTTP status flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (HTTPStatus) IsClientError ¶
func (s HTTPStatus) IsClientError() bool
IsClientError returns true if the status code represents a 4xx client error response.
func (HTTPStatus) IsServerError ¶
func (s HTTPStatus) IsServerError() bool
IsServerError returns true if the status code represents a 5xx server error response.
func (HTTPStatus) IsSuccess ¶
func (s HTTPStatus) IsSuccess() bool
IsSuccess returns true if the status code represents a 2xx success response.
func (HTTPStatus) MarshalText ¶
func (s HTTPStatus) MarshalText() ([]byte, error)
MarshalText encodes the HTTP status code into UTF-8 text bytes.
func (HTTPStatus) Predict ¶
func (s HTTPStatus) Predict() predict.Predictor
Predict returns HTTP status code autocompletion candidates.
func (HTTPStatus) String ¶
func (s HTTPStatus) String() string
String returns the HTTP status code formatted as a string.
func (HTTPStatus) Text ¶
func (s HTTPStatus) Text() string
Text returns the standard HTTP status reason text (e.g. OK, Not Found).
func (*HTTPStatus) UnmarshalText ¶
func (s *HTTPStatus) UnmarshalText(text []byte) error
UnmarshalText parses a numeric HTTP status code (100–599) or standard status text.
type Host ¶
type Host string
Host represents a hostname, domain name, or IP address with automatic host completion.
func (Host) Help ¶
Help returns the default value syntax description for host flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (Host) LookupIP ¶
LookupIP queries DNS for the IP addresses associated with the host, honoring ctx for cancellation and deadlines.
func (Host) MarshalText ¶
MarshalText encodes the host into UTF-8 text bytes.
func (Host) Predict ¶
Predict returns host autocompletion candidates from /etc/hosts, SSH config, and known_hosts.
func (*Host) UnmarshalText ¶
UnmarshalText sets the host string, trimming surrounding whitespace; empty input clears the value. It performs no validation: a host is checked only when it is used (e.g. LookupIP rejects a blank host with an error).
type MIMEType ¶
type MIMEType string
MIMEType represents an IANA media type string (e.g. application/json).
func (MIMEType) Help ¶
Help returns the default value syntax description for MIME type flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (MIMEType) MarshalText ¶
MarshalText encodes the media type into UTF-8 text bytes.
func (MIMEType) Subtype ¶
Subtype returns the subtype component (e.g. json in application/json; charset=utf-8).
func (MIMEType) Type ¶
Type returns the top-level media type component (e.g. application in application/json).
func (*MIMEType) UnmarshalText ¶
UnmarshalText parses and validates that the text is a valid MIME media type with a slash.
type NetInterface ¶
type NetInterface string
NetInterface represents a system network interface name.
func (NetInterface) Addrs ¶
func (n NetInterface) Addrs() ([]net.Addr, error)
Addrs returns the unicast interface addresses for the network interface.
func (NetInterface) Help ¶
func (n NetInterface) Help() string
Help returns the default value syntax description for network interface flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (NetInterface) Interface ¶
func (n NetInterface) Interface() (*net.Interface, error)
Interface queries the system for the underlying net.Interface.
func (NetInterface) MarshalText ¶
func (n NetInterface) MarshalText() ([]byte, error)
MarshalText encodes the network interface name into UTF-8 text bytes.
func (NetInterface) Predict ¶
func (n NetInterface) Predict() predict.Predictor
Predict returns network interface autocompletion candidates.
func (NetInterface) String ¶
func (n NetInterface) String() string
String returns the network interface name.
func (*NetInterface) UnmarshalText ¶
func (n *NetInterface) UnmarshalText(text []byte) error
UnmarshalText sets the network interface name.
type Port ¶
type Port uint16
Port represents a network service port (1–65535).
func (Port) Help ¶
Help returns the default value syntax description for port flags. The engine renders this text in the flag's help column when the field declares no help tag; a field with a help tag shows that text instead. Shells also show it as the description of the flag's completion candidates.
func (Port) IsPrivileged ¶
IsPrivileged returns true if the port is a system/privileged port (< 1024).
func (Port) MarshalText ¶
MarshalText encodes the port number into UTF-8 text bytes.
func (*Port) UnmarshalText ¶
UnmarshalText parses a numeric port (1–65535) or a well-known service name.