host

package
v2.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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

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

Host 限定域名的中间件

func New

func New(omitempty bool, domain ...string) *Host

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

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

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

func (*Host) Add

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

Add 添加新的域名

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

NOTE: 重复的值不会重复添加。

func (*Host) Delete

func (h *Host) Delete(domain string)

Delete 删除域名

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

func (*Host) Middleware

func (h *Host) Middleware(next http.Handler) http.Handler

Middleware 将当前中间件应用于 next

func (*Host) MiddlewareFunc

func (h *Host) MiddlewareFunc(next func(w http.ResponseWriter, r *http.Request)) http.Handler

MiddlewareFunc 将当前中间件应用于 next

type Switcher

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

Switcher 实现按域名进行路由

func NewSwitcher

func NewSwitcher() *Switcher

NewSwitcher 声明新的 Switcher 实例

func (*Switcher) AddHost

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

AddHost 添加域名信息

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

func (*Switcher) ServeHTTP

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

Jump to

Keyboard shortcuts

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