teaproxy

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 4, 2019 License: MIT Imports: 42 Imported by: 18

Documentation

Index

Constants

View Source
const (
	SchemeHTTP  = Scheme(1)
	SchemeHTTPS = Scheme(2)
)

Variables

View Source
var QPS = int32(0)

对外可读取的QPS

View Source
var ShareStaticDelivery = NewStaticDelivery()

公用的静态文件分发器

View Source
var SharedClientPool = NewClientPool()

客户端池单例

View Source
var SharedManager = NewManager()

共享的管理对象

View Source
var StatusCodeParser func(statusCode int, headers http.Header, respData []byte, parserScript string) (string, error) = nil

状态码筛选

Functions

func AddRequestHook

func AddRequestHook(hook *RequestHook)

添加Hook

func CallRequestAfterHook

func CallRequestAfterHook(req *Request, writer *ResponseWriter) (goNext bool)

执行After Hook

func CallRequestBeforeHook

func CallRequestBeforeHook(req *Request, writer *ResponseWriter) (goNext bool)

执行Before Hook

Types

type ClientPool

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

客户端池

func NewClientPool

func NewClientPool() *ClientPool

获取新对象

func (*ClientPool) Reset

func (this *ClientPool) Reset()

重置

type Listener

type Listener struct {
	IsChanged bool // 标记是否改变,用来在其他地方重启改变的监听器

	Scheme  Scheme // http & https
	Address string
	Error   error
	// contains filtered or unexported fields
}

代理服务监听器

func NewListener

func NewListener() *Listener

获取新对象

func (*Listener) ApplyServer added in v0.1.2

func (this *Listener) ApplyServer(server *teaconfigs.ServerConfig)

应用配置

func (*Listener) HasServer added in v0.1.2

func (this *Listener) HasServer(serverId string) bool

判断是否包含某个配置

func (*Listener) HasServers added in v0.1.2

func (this *Listener) HasServers() bool

是否包含配置

func (*Listener) Reload added in v0.1.2

func (this *Listener) Reload() error

刷新

func (*Listener) RemoveServer added in v0.1.2

func (this *Listener) RemoveServer(serverId string)

删除配置

func (*Listener) Reset added in v0.1.2

func (this *Listener) Reset()

重置所有配置

func (*Listener) Shutdown

func (this *Listener) Shutdown() error

关闭

func (*Listener) Start

func (this *Listener) Start() error

启动

type Manager added in v0.1.2

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

管理器

func NewManager added in v0.1.2

func NewManager() *Manager

获取新对象

func (*Manager) ApplyServer added in v0.1.2

func (this *Manager) ApplyServer(server *teaconfigs.ServerConfig)

添加Server

func (*Manager) FindServer added in v0.1.2

func (this *Manager) FindServer(serverId string) *teaconfigs.ServerConfig

查找Server

func (*Manager) FindServerErrors added in v0.1.2

func (this *Manager) FindServerErrors(serverId string) []string

查找Server相关错误

func (*Manager) Reload added in v0.1.2

func (this *Manager) Reload() error

重载配置

func (*Manager) RemoveServer added in v0.1.2

func (this *Manager) RemoveServer(serverId string)

删除Server

func (*Manager) Restart added in v0.1.2

func (this *Manager) Restart() error

重启

func (*Manager) Shutdown added in v0.1.2

func (this *Manager) Shutdown() error

停止

func (*Manager) Start added in v0.1.2

func (this *Manager) Start() error

启动

func (*Manager) Wait added in v0.1.2

func (this *Manager) Wait()

等待

type NamedServer added in v0.1.2

type NamedServer struct {
	Name   string                   // 匹配后的域名
	Server *teaconfigs.ServerConfig // 匹配后的服务配置
}

域名和服务映射

type RedirectError

type RedirectError struct {
}

func (*RedirectError) Error

func (this *RedirectError) Error() string

type Request

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

请求定义 HTTP HEADER RFC: https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

func NewRequest

func NewRequest(rawRequest *http.Request) *Request

获取新的请求

func (*Request) CachePolicy

func (this *Request) CachePolicy() *shared.CachePolicy

func (*Request) Format

func (this *Request) Format(source string) string

利用请求参数格式化字符串

func (*Request) IsCacheEnabled

func (this *Request) IsCacheEnabled() bool

判断缓存策略是否有效

func (*Request) IsWatching

func (this *Request) IsWatching() bool

判断是否在监控

func (*Request) Raw added in v0.1.2

func (this *Request) Raw() *http.Request

获取原始的请求

func (*Request) SetAttr added in v0.1.2

func (this *Request) SetAttr(key string, value string)

设置属性

func (*Request) SetCacheEnabled

func (this *Request) SetCacheEnabled()

func (*Request) SetCachePolicy

func (this *Request) SetCachePolicy(config *shared.CachePolicy)

func (*Request) SetHost added in v0.1.2

func (this *Request) SetHost(host string)

设置Host

func (*Request) SetIsWatching

func (this *Request) SetIsWatching(isWatching bool)

设置监控状态

func (*Request) SetURI added in v0.1.2

func (this *Request) SetURI(uri string)

设置URI

type RequestHook

type RequestHook struct {
	BeforeRequest func(req *Request, writer *ResponseWriter) (goNext bool)
	AfterRequest  func(req *Request, writer *ResponseWriter) (goNext bool)
}

请求Hook定义

type ResponseWriter

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

响应Writer

func NewResponseWriter

func NewResponseWriter(httpResponseWriter http.ResponseWriter) *ResponseWriter

包装对象

func (*ResponseWriter) AddHeaders

func (this *ResponseWriter) AddHeaders(header http.Header)

添加一组Header

func (*ResponseWriter) Body

func (this *ResponseWriter) Body() []byte

读取拷贝的Body数据

func (*ResponseWriter) BodyIsCopying

func (this *ResponseWriter) BodyIsCopying() bool

判断是否在拷贝Body数据

func (*ResponseWriter) Close

func (this *ResponseWriter) Close()

关闭

func (*ResponseWriter) Gzip

func (this *ResponseWriter) Gzip(level uint8, minLength int64)

设置Gzip

func (*ResponseWriter) Header

func (this *ResponseWriter) Header() http.Header

获取Header

func (*ResponseWriter) HeaderData

func (this *ResponseWriter) HeaderData() []byte

读取Header二进制数据

func (*ResponseWriter) Prepare

func (this *ResponseWriter) Prepare(size int64)

准备输出

func (*ResponseWriter) Raw

func (this *ResponseWriter) Raw() http.ResponseWriter

包装前的原始的Writer

func (*ResponseWriter) SentBodyBytes

func (this *ResponseWriter) SentBodyBytes() int64

读取发送的字节数

func (*ResponseWriter) SetBodyCopying

func (this *ResponseWriter) SetBodyCopying(b bool)

设置拷贝Body数据

func (*ResponseWriter) StatusCode

func (this *ResponseWriter) StatusCode() int

读取状态码

func (*ResponseWriter) Write

func (this *ResponseWriter) Write(data []byte) (n int, err error)

写入数据

func (*ResponseWriter) WriteHeader

func (this *ResponseWriter) WriteHeader(statusCode int)

写入状态码

type Scheme added in v0.1.2

type Scheme = uint8

type StaticDelivery added in v0.1.2

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

静态文件分发器

func NewStaticDelivery added in v0.1.2

func NewStaticDelivery() *StaticDelivery

获取新对象

func (*StaticDelivery) Read added in v0.1.2

func (this *StaticDelivery) Read(path string, stat os.FileInfo) (reader io.Reader, shouldClose bool, err error)

读取

type StaticFileCache added in v0.1.2

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

静态文件缓存

Jump to

Keyboard shortcuts

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