teaproxy

package
v0.1.72 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2019 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TCPClientMaxAttempts = 3   // 失败最多尝试次数
	TCPClientStreamSize  = 128 // 读取客户端数据的队列长度
)

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 SharedTunnelManager = NewTunnelManager()

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

获取新对象

type Listener

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

	Scheme  Scheme // http, https, tcp, tcp+tls
	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) CloseTCPClient added in v0.1.6

func (this *Listener) CloseTCPClient(lAddr string) error

关闭某个TCP连接

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

启动

func (*Listener) TCPClients added in v0.1.6

func (this *Listener) TCPClients(maxSize int) []*TCPClient

获取TCP连接列表

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) FindAllServers added in v0.1.7

func (this *Manager) FindAllServers() []*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) FindServerListeners added in v0.1.6

func (this *Manager) FindServerListeners(serverId string) []*Listener

查找Server对应的Listener

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 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

func (*Request) SetVarMapping added in v0.1.5

func (this *Request) SetVarMapping(varName string, varValue string)

添加自定义变量

func (*Request) WriteResponseHeaders added in v0.1.5

func (this *Request) WriteResponseHeaders(writer *ResponseWriter, statusCode int)

输出自定义Response Header

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) Reset added in v0.1.6

func (this *ResponseWriter) Reset(httpResponseWriter http.ResponseWriter)

重置

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)

写入状态码

func (*ResponseWriter) WriteString added in v0.1.6

func (this *ResponseWriter) WriteString(s string) (n int, err error)

写入字符串

type Scheme added in v0.1.2

type Scheme = uint8

协议

const (
	SchemeHTTP   Scheme = 1
	SchemeHTTPS  Scheme = 2
	SchemeTCP    Scheme = 3
	SchemeTCPTLS Scheme = 4
)

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
}

静态文件缓存

type TCPClient added in v0.1.6

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

TCP连接客户端

func NewTCPClient added in v0.1.6

func NewTCPClient(serverPool func() *teaconfigs.ServerConfig, conn net.Conn) *TCPClient

创建新的客户端对象

func (*TCPClient) Close added in v0.1.6

func (this *TCPClient) Close() error

关闭

func (*TCPClient) Connect added in v0.1.6

func (this *TCPClient) Connect()

连接后端服务器

func (*TCPClient) LConn added in v0.1.6

func (this *TCPClient) LConn() net.Conn

获取左连接 - 客户端

func (*TCPClient) RConn added in v0.1.6

func (this *TCPClient) RConn() net.Conn

获取右连接 - 后端服务器

func (*TCPClient) ReadSpeed added in v0.1.6

func (this *TCPClient) ReadSpeed() int64

获取读取的速度

func (*TCPClient) WriteSpeed added in v0.1.6

func (this *TCPClient) WriteSpeed() int64

获取写入的速度

type Tunnel added in v0.1.5

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

隧道状态管理

func NewTunnel added in v0.1.5

func NewTunnel(config *teaconfigs.TunnelConfig) *Tunnel

获取新对象

func (*Tunnel) Close added in v0.1.5

func (this *Tunnel) Close() error

关闭

func (*Tunnel) CountConnections added in v0.1.5

func (this *Tunnel) CountConnections() int

获取连接数量

func (*Tunnel) Id added in v0.1.5

func (this *Tunnel) Id() string

获取当前Tunnel的ID

func (*Tunnel) Start added in v0.1.5

func (this *Tunnel) Start() error

启动

func (*Tunnel) Write added in v0.1.5

func (this *Tunnel) Write(req *http.Request) (resp *http.Response, err error)

发送请求

type TunnelConnection added in v0.1.5

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

隧道连接

func NewTunnelConnection added in v0.1.5

func NewTunnelConnection(conn net.Conn, tunnelConfig *teaconfigs.TunnelConfig) *TunnelConnection

获取新对象

func (*TunnelConnection) Close added in v0.1.5

func (this *TunnelConnection) Close() error

关闭

func (*TunnelConnection) IsAuthenticated added in v0.1.6

func (this *TunnelConnection) IsAuthenticated() bool

判断是否已认证

func (*TunnelConnection) OnClose added in v0.1.6

func (this *TunnelConnection) OnClose(handler func(tunnelConn *TunnelConnection))

设置关闭回调

func (*TunnelConnection) Ping added in v0.1.6

func (this *TunnelConnection) Ping() error

Ping客户端

func (*TunnelConnection) RemoteAddr added in v0.1.6

func (this *TunnelConnection) RemoteAddr() string

远程地址

func (*TunnelConnection) Write added in v0.1.5

func (this *TunnelConnection) Write(req *http.Request) (*http.Response, error)

发送请求

type TunnelManager added in v0.1.5

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

Tunnel管理器

func NewTunnelManager added in v0.1.5

func NewTunnelManager() *TunnelManager

获取新对象

func (*TunnelManager) FindTunnel added in v0.1.5

func (this *TunnelManager) FindTunnel(serverId, tunnelId string) *Tunnel

查找Tunnel

func (*TunnelManager) OnAttach added in v0.1.5

func (this *TunnelManager) OnAttach(server *teaconfigs.ServerConfig)

加载

func (*TunnelManager) OnDetach added in v0.1.5

func (this *TunnelManager) OnDetach(server *teaconfigs.ServerConfig)

卸载

type TunnelResponseBody added in v0.1.5

type TunnelResponseBody struct {
	io.ReadCloser
	// contains filtered or unexported fields
}

Tunnel响应包装,主要是为了覆盖Close()方法

func (*TunnelResponseBody) Close added in v0.1.5

func (this *TunnelResponseBody) Close() error

关闭

Jump to

Keyboard shortcuts

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