network

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPMethods

func HTTPMethods() predict.Predictor

HTTPMethods configures completion of standard HTTP request methods (GET, POST, PUT, DELETE, etc.).

func HTTPStatusCodes

func HTTPStatusCodes() predict.Predictor

HTTPStatusCodes configures completion of standard HTTP status codes with human-readable descriptions.

func Hosts

func Hosts() predict.Predictor

Hosts configures completion of hostnames from /etc/hosts, SSH known_hosts, and SSH config. Patterns and negations (entries containing "*", "?", or "!") are not offered.

func MIMETypes

func MIMETypes() predict.Predictor

MIMETypes configures completion of standard IANA MIME / media types.

func NetInterfaces

func NetInterfaces() predict.Predictor

NetInterfaces configures completion of network interface names discovered on the system.

func Ports

func Ports() predict.Predictor

Ports configures completion of well-known TCP/UDP service ports with descriptive annotations.

func RegisterInterface

func RegisterInterface[T any](app *conga.App[T])

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

func RegisterNetInterface[T any](app *conga.App[T])

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

func (h Host) Help() string

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

func (h Host) LookupIP(ctx context.Context) ([]net.IP, error)

LookupIP queries DNS for the IP addresses associated with the host, honoring ctx for cancellation and deadlines.

func (Host) MarshalText

func (h Host) MarshalText() ([]byte, error)

MarshalText encodes the host into UTF-8 text bytes.

func (Host) Predict

func (h Host) Predict() predict.Predictor

Predict returns host autocompletion candidates from /etc/hosts, SSH config, and known_hosts.

func (Host) String

func (h Host) String() string

String returns the hostname or IP string.

func (*Host) UnmarshalText

func (h *Host) UnmarshalText(text []byte) error

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

func (m MIMEType) Help() string

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

func (m MIMEType) MarshalText() ([]byte, error)

MarshalText encodes the media type into UTF-8 text bytes.

func (MIMEType) Predict

func (m MIMEType) Predict() predict.Predictor

Predict returns media type autocompletion candidates.

func (MIMEType) String

func (m MIMEType) String() string

String returns the media type string.

func (MIMEType) Subtype

func (m MIMEType) Subtype() string

Subtype returns the subtype component (e.g. json in application/json; charset=utf-8).

func (MIMEType) Type

func (m MIMEType) Type() string

Type returns the top-level media type component (e.g. application in application/json).

func (*MIMEType) UnmarshalText

func (m *MIMEType) UnmarshalText(text []byte) error

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

func (p Port) Help() string

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) Int

func (p Port) Int() int

Int returns the port number as an integer.

func (Port) IsPrivileged

func (p Port) IsPrivileged() bool

IsPrivileged returns true if the port is a system/privileged port (< 1024).

func (Port) MarshalText

func (p Port) MarshalText() ([]byte, error)

MarshalText encodes the port number into UTF-8 text bytes.

func (Port) Predict

func (p Port) Predict() predict.Predictor

Predict returns service port autocompletion candidates.

func (Port) String

func (p Port) String() string

String returns the port number formatted as a string.

func (*Port) UnmarshalText

func (p *Port) UnmarshalText(text []byte) error

UnmarshalText parses a numeric port (1–65535) or a well-known service name.

Jump to

Keyboard shortcuts

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