middleware

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2018 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// HitForPassTTL hit for pass的有效期
	HitForPassTTL = 600
)

Variables

View Source
var (
	// ErrDirectorNotFound 未找到可用的director
	ErrDirectorNotFound = pike.NewHTTPError(http.StatusNotImplemented, "director not found")
	// ErrRequestStatusNotSet 未设置请求的status
	ErrRequestStatusNotSet = pike.NewHTTPError(http.StatusNotImplemented, "request status not set")

	// ErrIdentityNotSet 未设置Identity
	ErrIdentityNotSet = pike.NewHTTPError(http.StatusNotImplemented, "identity not set")

	// ErrResponseNotSet 未设置response
	ErrResponseNotSet = pike.NewHTTPError(http.StatusNotImplemented, "response not set")

	// ErrContentEncodingNotSupport 未支持此content encoding
	ErrContentEncodingNotSupport = pike.NewHTTPError(http.StatusNotImplemented, "content enconding not support")
	// ErrNoBackendAvaliable 没有可用的backend
	ErrNoBackendAvaliable = pike.NewHTTPError(http.StatusServiceUnavailable, "no backend avaliable")
	// ErrGatewayTimeout 网关超时
	ErrGatewayTimeout = pike.NewHTTPError(http.StatusGatewayTimeout, "gateway timeout")
	// ErrTooManyRequest 太多的请求正在处理中
	ErrTooManyRequest = pike.NewHTTPError(http.StatusTooManyRequests, "too many request is handling")
)
View Source
var (
	// DefaultRecoverConfig is the default Recover middleware config.
	DefaultRecoverConfig = RecoverConfig{
		StackSize:         4 << 10,
		DisableStackAll:   false,
		DisablePrintStack: false,
	}
)

Functions

func CacheFetcher

func CacheFetcher(config CacheFetcherConfig, client *cache.Client) pike.Middleware

CacheFetcher 从缓存中获取数据

func CreateErrorHandler

func CreateErrorHandler(client *cache.Client) pike.ErrorHandler

CreateErrorHandler 创建异常处理函数

func DirectorPicker

func DirectorPicker(config DirectorPickerConfig, directors pike.Directors) pike.Middleware

DirectorPicker 根据请求的参数获取相应的director 判断director是否符合是顺序查询,因此需要将directors先根据优先级排好序

func Dispatcher

func Dispatcher(config DispatcherConfig, client *cache.Client) pike.Middleware

Dispatcher 对响应数据做缓存,复制等处理

func FreshChecker

func FreshChecker(config FreshCheckerConfig) pike.Middleware

FreshChecker 判断请求是否fresh(304)

func HeaderSetter

func HeaderSetter(config HeaderSetterConfig) pike.Middleware

HeaderSetter 设置响应头

func Identifier

func Identifier(config IdentifierConfig, client *cache.Client) pike.Middleware

Identifier 对请求的参数校验,生成各类状态值

- 判断请求状态,生成status - 对于状态非Pass的请求,根据request url 生成identity

func Initialization

func Initialization(config InitializationConfig) pike.Middleware

Initialization 相关一些初始化的操作

func Logger

func Logger(config LoggerConfig) pike.Middleware

Logger logger中间件

func Ping

func Ping(config PingConfig) pike.Middleware

Ping ping middleware function

func Proxy

func Proxy(config ProxyConfig) pike.Middleware

Proxy returns a Proxy middleware with config.

func Recover

func Recover(config RecoverConfig) pike.Middleware

Recover 异常捕获,异常程序shutdown

Types

type CacheFetcherConfig

type CacheFetcherConfig struct {
}

CacheFetcherConfig cache fetcher配置

type DirectorPickerConfig

type DirectorPickerConfig struct {
}

DirectorPickerConfig director配置

type DispatcherConfig

type DispatcherConfig struct {
	// 压缩数据类型
	CompressTypes []string
	// 最小压缩
	CompressMinLength int
	// CompressLevel 数据压缩级别
	CompressLevel int
}

DispatcherConfig dipatcher的配置

type FreshCheckerConfig

type FreshCheckerConfig struct {
}

FreshCheckerConfig freshChecker配置

type HeaderSetterConfig

type HeaderSetterConfig struct {
}

HeaderSetterConfig header setter的配置

type IdentifierConfig

type IdentifierConfig struct {
}

IdentifierConfig 定义配置

type InitializationConfig

type InitializationConfig struct {
	Header        []string
	RequestHeader []string
	Concurrency   int
}

InitializationConfig 初始化配置

type LoggerConfig

type LoggerConfig struct {
	Writer    httplog.Writer
	LogFormat string
}

LoggerConfig logger配置

type PingConfig

type PingConfig struct {
	URL string
}

PingConfig ping的配置

type ProxyConfig

type ProxyConfig struct {

	// Rewrites defines URL path rewrite rules. The values captured in asterisk can be
	// retrieved by index e.g. $1, $2 and so on.
	// Examples:
	// "/old":              "/new",
	// "/api/*":            "/$1",
	// "/js/*":             "/public/javascripts/$1",
	// "/users/*/orders/*": "/user/$1/order/$2",
	Rewrites []string

	// ETag 是否生成ETag
	ETag bool

	// Timeout proxy的连接超时
	Timeout time.Duration
	// contains filtered or unexported fields
}

ProxyConfig defines the config for Proxy middleware.

type ProxyTarget

type ProxyTarget struct {
	Name string
	URL  *url.URL
}

ProxyTarget defines the upstream target.

type RecoverConfig

type RecoverConfig struct {
	// Size of the stack to be printed.
	// Optional. Default value 4KB.
	StackSize int `yaml:"stack_size"`

	// DisableStackAll disables formatting stack traces of all other goroutines
	// into buffer after the trace for the current goroutine.
	// Optional. Default value false.
	DisableStackAll bool `yaml:"disable_stack_all"`

	// DisablePrintStack disables printing stack trace.
	// Optional. Default value as false.
	DisablePrintStack bool `yaml:"disable_print_stack"`
}

RecoverConfig recover config

Jump to

Keyboard shortcuts

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