host

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package host 提供了限定访问域名的中间件

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Host added in v1.7.0

type Host struct {
	// contains filtered or unexported fields
}

Host 限定域名的中间件

func New

func New(next http.Handler, domains ...string) *Host

New 声明一个限定域名的中间件

若请求的域名不允许,会返回 404 错误。 若 domains 为空,则任何请求都将返回 404。

仅会将域名与 domains 进行比较,端口与协议都将不参写比较。

func (*Host) Add added in v1.7.0

func (h *Host) Add(domain ...string)

Add 添加新的域名

domain 可以是泛域名,比如 *.example.com,但不能是 s1.*.example.com。

func (*Host) Delete added in v1.7.0

func (h *Host) Delete(domain string)

Delete 删除域名

NOTE:如果不存在,则不作任何改变。

func (*Host) Omitempty added in v1.7.0

func (h *Host) Omitempty(v bool)

Omitempty 当域名列表为空时是否对所有访问都采用许可的方式进行

默认情况下,如果域名列表为空,则会阻止所有的访问。

func (*Host) ServeHTTP added in v1.7.0

func (h *Host) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Switcher added in v1.2.0

type Switcher struct {
	// contains filtered or unexported fields
}

Switcher 实现按域名进行路由

func NewSwitcher added in v1.2.0

func NewSwitcher() *Switcher

NewSwitcher 声明新的 Switcher 实例

func (*Switcher) AddHost added in v1.2.0

func (s *Switcher) AddHost(h http.Handler, domain ...string)

AddHost 添加域名信息

domain 可以是泛域名,比如 *.example.com,但不能是 s1.*.example.com

func (*Switcher) ServeHTTP added in v1.2.0

func (s *Switcher) ServeHTTP(w http.ResponseWriter, r *http.Request)

Directories

Path Synopsis
Package switcher 按域名进行路由分类
Package switcher 按域名进行路由分类

Jump to

Keyboard shortcuts

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