hostmatch

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package hostmatch parses and matches the host entries that appear in an endpoint's `hosts = [...]` list. Entries may be exact `api.foo.com`, port-qualified `api.foo.com:443`, IP literals `10.0.0.5`, IPv6 literals `[fd00::1]:22`, or wildcard suffixes `*.foo.com` (optionally port-qualified).

Wildcards take the form `*.<suffix>`: a single `*` at the leftmost label, immediately followed by `.`, followed by a non-empty hostname containing no further metacharacters. `*.foo.com` matches any name that ends in `.foo.com` and has at least one character before that suffix — both `s3.foo.com` and `s3.us-east-1.foo.com` match, but the bare `foo.com` does not. Single-label restriction (RFC 6125 TLS cert wildcards) is deliberately NOT applied: the matching here is for endpoint routing, not certificate validation, and the operator use case (e.g. `*.amazonaws.com`) needs to span multiple label depths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsWildcardHost

func IsWildcardHost(entry string) bool

IsWildcardHost reports whether the host portion of entry is a wildcard pattern. entry may carry a `:port` suffix.

func MatchWildcard

func MatchWildcard(pattern, hostname string) bool

MatchWildcard reports whether the lowercased hostname matches the wildcard pattern. pattern must be a validated `*.<suffix>` form; hostname must be a bare host (no port). Both should already be lowercased — this function does no case folding.

func SplitHostPort

func SplitHostPort(entry string) (host, port string, err error)

SplitHostPort separates a `host[:port]` entry into its parts. For bare hosts it returns port="". Unlike net.SplitHostPort it does NOT error on the bare-host case — the caller (an endpoint's hosts list) routinely accepts both forms.

Wildcard hosts like `*.foo.com` pass through unchanged in the host return; `*.foo.com:443` separates as host=`*.foo.com`, port=`443`.

func ValidateHost

func ValidateHost(entry string) error

ValidateHost checks that entry is a syntactically valid host entry. Accepts exact hostnames, IP literals, port-qualified forms, and `*.<suffix>` wildcards. Returns an error explaining what's wrong when entry doesn't fit any of those.

Types

This section is empty.

Jump to

Keyboard shortcuts

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