hostname

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 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 hostname 规范化与校验按 Host 头或 TLS SNI 匹配的域名。

浏览器发出的 Host 与 SNI 总是小写、不带方括号的 IPv6、国际化域名为 punycode, 这里把配置中的写法统一成同样的形式,保存时就能发现永远匹配不上的写法(带端口、路径、@ 等)。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CapturePattern added in v0.6.6

func CapturePattern(pattern, host string) (string, bool)

CapturePattern 匹配已规范化的 Web 站点域名,返回 * 捕获的部分。 *.example.com 与末尾整段的 audiobook.* 匹配一段或多段;中间整段 * 匹配恰好一段; 段内的 * 只匹配该段内的零个或多个字符,匹配后的段仍须是合法的段。

func Normalize

func Normalize(d string, wildcard bool) (string, bool)

Normalize 规范化一条域名:去掉空白与首尾的点,转为小写;IPv6 去掉方括号并转为标准写法; 国际化域名转为 punycode。wildcard 为 true 时允许单独的 * 与 *.example.com。 空字符串原样返回 ok;不是合法主机名、IP 或通配写法时 ok 为 false。

func NormalizePattern added in v0.6.6

func NormalizePattern(d string) (string, bool)

NormalizePattern 用于 Web 站点域名,在 Normalize 的写法(精确域名、IP、*、*.example.com)之外, 允许任意一段中出现一个 *:

  • 段内通配 api-*.example.com、audiobook.api-*.example.com:* 只匹配该段内的零个或多个字符;
  • 中间整段 audiobook.*.example.com:* 匹配恰好一段;
  • 末尾整段 audiobook.*:* 匹配后面的一段或多段(audiobook.example.com、audiobook.home.lan)。

整个规则只能有一个 *,重定向变量 {1} 取它匹配到的部分。 Normalize 保持不变,避免其他只支持 *.example.com 的模块接受无法匹配的配置。

Types

This section is empty.

Jump to

Keyboard shortcuts

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