Documentation
¶
Index ¶
- type Config
- type Conn
- type HandleFunc
- type Listen
- type Server
- type ServerPublic
- type ServerTLS
- type ServerTLSFile
- type Servers
- type Site
- type SiteDirectory
- type SiteDynamic
- type SiteForward
- type SiteForwards
- type SiteHeader
- type SiteHeaderType
- type SiteLog
- type SiteLogLevel
- type SitePlugin
- type SitePluginTLS
- type SitePlugins
- type SitePublic
- func (T *SitePublic) ConfigSiteDynamic(origin *SiteDynamic, handle HandleFunc) bool
- func (T *SitePublic) ConfigSiteForward(origin *SiteForwards, handle HandleFunc) bool
- func (T *SitePublic) ConfigSiteHeader(origin *SiteHeader, handle HandleFunc) bool
- func (T *SitePublic) ConfigSitePlugin(origin *SitePlugin, name string, handle HandleFunc) bool
- func (T *SitePublic) ConfigSiteSession(origin *SiteSession, handle HandleFunc) bool
- type SiteSession
- type Sites
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
Servers Servers `yaml:"Servers"` // 服务器集
Sites Sites `yaml:"Sites"` // 站点集
// contains filtered or unexported fields
}
Config 配置
func (*Config) ParseFile ¶
ParseFile 解析服务器配置文件,一个 JSON 格式的文件。
参: file string 文件 返: error 错误,如果文件无法打开,或无法解析的情况
func (*Config) ParseFiles ¶
func (*Config) ParseReader ¶
ParseReader 解析服务器配置数据,一个 JSON 格式的数据。
参: r io.Reader 读接口 返: error 错误,如果无法解析的情况
func (*Config) ParseReaderTOML ¶ added in v3.3.0
ParseReaderTOML 以严格模式解析 TOML 文件。
type Conn ¶
type Conn struct {
// 引用公共配置后,该以结构中的CC和CS如果也有设置,将会使用优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
Deadline int64 `yaml:"Deadline"` // 设置读写超时(毫秒单位)
WriteDeadline int64 `yaml:"WriteDeadline"` // 设置写入超时(毫秒单位)
ReadDeadline int64 `yaml:"ReadDeadline"` // 设置读取超时(毫秒单位)
DisableKeepAlive bool `yaml:"DisableKeepAlive"` // 禁止长连接
KeepAlivePeriod int64 `yaml:"KeepAlivePeriod"` // 保持连接超时(毫秒单位)
Linger int `yaml:"Linger"` // 连接关闭后,等待发送或待确认的数据(秒单位)。如果 sec > 0,经过sec秒后,所有剩余的未发送数据都可能会被丢弃。则与sec < 0 一样在后台发送数据。
Delay bool `yaml:"Delay"` // 设置操作系统是否延迟发送数据包,(false 无延迟)
ReadBuffer int `yaml:"ReadBuffer"` // 在缓冲区读取数据大小
WriteBuffer int `yaml:"WriteBuffer"` // 写入数据到缓冲区大小
}
Conn 连接相关参数
type HandleFunc ¶ added in v3.3.0
HandleFunc 类型定义。
type Listen ¶
type Listen struct {
Status bool `yaml:"Status"` // 状态,是否启动此服务器
CC Conn `yaml:"CC"` // 连接设置
CS Server `yaml:"CS"` // 服务器设置
}
Listen 监听配置
type Server ¶
type Server struct {
// 引用公共配置后,该结构中的 CC 和 CS 如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
ReadTimeout int64 `yaml:"ReadTimeout"` // 设置读取超时(毫秒单位)
WriteTimeout int64 `yaml:"WriteTimeout"` // 设置写入超时(毫秒单位)
ReadHeaderTimeout int64 `yaml:"ReadHeaderTimeout"` // 读取标头超时(毫秒单位)
IdleTimeout int64 `yaml:"IdleTimeout"` // 保持连接空闲超时,如果为0,使用 ReadTimeout,(毫秒单位)
MaxHeaderBytes int `yaml:"MaxHeaderBytes"` // 如果0,最大请求头的大小,http.DefaultMaxHeaderBytes
DisableKeepAlives bool `yaml:"DisableKeepAlives"` // 禁止客户端Keep-Alive
ShutdownConn bool `yaml:"ShutdownConn"` // 服务器关闭监听,不会即时关闭正在下载的连接。空闲后再关闭。(默认即时关闭)
DisableGeneralOptionsHandler bool `yaml:"DisableGeneralOptionsHandler"` // 如果为真,将“OPTIONS *”请求传递给处理程序,否则响应 200 OK 和 Content-Length: 0。
TLS *ServerTLS `yaml:"TLS"` // TLS
}
Server 服务器参数
type ServerPublic ¶
type ServerPublic struct {
CC map[string]Conn `yaml:"CC"` // 连接设置
CS map[string]Server `yaml:"CS"` // 服务器设置
}
ServerPublic 公共服务器配置
func (*ServerPublic) ConfigConn ¶
func (T *ServerPublic) ConfigConn(origin *Conn, handle func(name string, dsc, src reflect.Value) bool) bool
ConfigConn 将公共连接配置合并到 origin(origin 非零字段优先)。 返回 true 表示成功合并。并发安全(读锁保护 map 查找)。
func (*ServerPublic) ConfigServer ¶
func (T *ServerPublic) ConfigServer(origin *Server, handle func(name string, dsc, src reflect.Value) bool) bool
ConfigServer 优化版本(关键改动)
type ServerTLS ¶
type ServerTLS struct {
RootCAs []ServerTLSFile `yaml:"RootCAs"` // 服务端证书文件
NextProtos []string `yaml:"NextProtos"` // http版本
CipherSuites []uint16 `yaml:"CipherSuites"` // 密码套件(仅影响 TLS 1.0–1.2;TLS 1.3 由运行时固定安全套件处理,不可配置)
SessionTicketsDisabled bool `yaml:"SessionTicketsDisabled"` // 设置为 true 可禁用会话票证 (恢复) 支持。
SetSessionTicketKeys [][32]byte `yaml:"SetSessionTicketKeys"` // 会话恢复票证
DynamicRecordSizingDisabled bool `yaml:"DynamicRecordSizingDisabled"` // 禁用TLS动态记录自适应大小
MinVersion uint16 `yaml:"MinVersion"` // 最小SSL/TLS版本。如果为零,则SSLv3的被取为最小(现代 Go 实际最低为 TLS 1.0,推荐 TLS 1.2+)。
MaxVersion uint16 `yaml:"MaxVersion"` // 最大SSL/TLS版本。如果为零,则该包所支持的最高版本被使用。
ClientCAs []string `yaml:"ClientCAs"` // 客户端拥有的“权威组织”证书的列表。(Server/Client端使用)
}
ServerTLS TLS 相关配置
func (*ServerTLS) CipherSuitesAuto ¶
func (T *ServerTLS) CipherSuitesAuto()
CipherSuitesAuto 根据 MinVersion/MaxVersion 自动填充安全密码套件。 仅填充 TLS 1.0–1.2 套件;TLS 1.3 套件由 crypto/tls 自动管理且不可配置。 注意:若多个 Server 共享同一 *ServerTLS 指针,首次并发调用存在竞态窗口, 建议在配置加载阶段单线程调用。方法本身对已填充的 CipherSuites 直接返回。
type ServerTLSFile ¶
type ServerTLSFile struct {
CertFile string `yaml:"CertFile"` // 证书文件
KeyFile string `yaml:"KeyFile"` // key 文件地址
}
ServerTLSFile 证书文件对
type Servers ¶
type Servers struct {
Public ServerPublic `yaml:"Public"`
Listen map[string]Listen `yaml:"Listen"`
}
Servers 服务器集合
type Site ¶
type Site struct {
Status bool `yaml:"Status"` // 状态,是否启动此站点
Name string `yaml:"Name"` // 站点别名
Identity string `yaml:"Identity"` // 站点维一码,可以说是池名
Host []string `yaml:"Host"` // 域名绑定
Forward map[string]SiteForwards `yaml:"Forward"` // 转发
Plugin SitePlugins `yaml:"Plugin"` // 插件
Directory SiteDirectory `yaml:"Directory"` // 目录
IndexFile []string `yaml:"IndexFile"` // 默认页
Dynamic SiteDynamic `yaml:"Dynamic"`
Header SiteHeader `yaml:"Header"` // HTTP头
Log SiteLog `yaml:"Log"` // 日志
ErrorPage map[string]string `yaml:"ErrorPage"` // 错误页
Session SiteSession `yaml:"Session"` // 会话
}
Site 配置-站点
type SiteDirectory ¶
type SiteDirectory struct {
Root string `yaml:"Root"` // 主目录
Virtual []string `yaml:"Virtual"` // 虚目录
}
SiteDirectory 配置-目录
func (*SiteDirectory) RootDir ¶
func (T *SiteDirectory) RootDir(upath string) string
RootDir 根目录
r *http.Request 请求 string 根目录路径
type SiteDynamic ¶
type SiteDynamic struct {
// 引用公共配置后,该结构中的字段如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
Ext []string `yaml:"Ext"` // 动态文件后缀
Cache bool `yaml:"Cache"` // 动态文件缓存解析,非缓存执行
CacheParseTimeout int64 `yaml:"CacheParseTimeout"` // 动态文件缓存解析超时,(秒为单位)
CacheStaticFileDir string `yaml:"CacheStaticFileDir"` // 缓存静态文件目录,仅适于 markdown 转 HTML
CacheStaticTimeout int64 `yaml:"CacheStaticTimeout"` // 缓存静态超时,(秒为单位)
}
SiteDynamic 动态相关配置
type SiteForward ¶
type SiteForward struct {
Status bool `yaml:"Status"` // 启用或禁止
Path []string `yaml:"Path"` // 多种路径匹配
ExcludePath []string `yaml:"ExcludePath"` // 排除多种路径匹配
RePath string `yaml:"RePath"` // 重写路径
RedirectCode int `yaml:"RedirectCode"` // 重定向状态码,默认不转向
End bool `yaml:"End"` // 不进行二次匹配/转发
// contains filtered or unexported fields
}
SiteForward 配置-转发-配置
func (*SiteForward) Compile ¶
func (T *SiteForward) Compile() (fw *vweb.ForwardRewriter, err error)
type SiteForwards ¶
type SiteForwards struct {
// 引用公共配置后,该结构中的字段如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
List []SiteForward `yaml:"List"`
}
SiteForwards 转发集合
type SiteHeader ¶
type SiteHeader struct {
// 引用公共配置后,该结构中的字段如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
Static map[string]SiteHeaderType `yaml:"Static"` // 静态 Header,key 形如 ".html"
Dynamic map[string]SiteHeaderType `yaml:"Dynamic"` // 动态 Header,key 形如 ".html"
MIME map[string]string `yaml:"MIME"` // MIME 类型
}
SiteHeader 配置-标头
type SiteHeaderType ¶
type SiteHeaderType struct {
Header map[string][]string `yaml:"Header"` // Header
PageExpired int64 `yaml:"PageExpired"` // 页面过期(秒单位)
}
SiteHeaderType 配置-标头-类型
type SiteLog ¶
type SiteLog struct {
Level SiteLogLevel `yaml:"Level"` // 级别
Directory string `yaml:"Directory"` // 目录
}
SiteLog 配置-日志,这个功能后面待加。
type SiteLogLevel ¶
type SiteLogLevel int
SiteLogLevel 配置-日志-级别
const (
SiteLogLevelDisable SiteLogLevel = iota // 禁用日志记录,默认不开启
)
type SitePlugin ¶
type SitePlugin struct {
// 引用公共配置后,该结构中的字段如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
Status bool `yaml:"Status"` // 状态,是否启用
// 公共
Addr string `yaml:"Addr"` // 地址
LocalAddr string `yaml:"LocalAddr"` // 本地拨号 IP
Timeout int64 `yaml:"Timeout"` // 拨号超时(毫秒单位)
KeepAlive int64 `yaml:"KeepAlive"` // 保持连接超时(毫秒单位)
FallbackDelay int64 `yaml:"FallbackDelay"` // 后退延时,等待双协议栈延时,(毫秒单位,默认 300ms)
IdeConn int `yaml:"IdeConn"` // 空闲连接数(历史字段名,保持导出兼容)
// RPC
Path string `yaml:"Path"` // 路径
MaxConn int `yaml:"MaxConn"` // 最大连接数
// HTTP
ProxyURL string `yaml:"ProxyURL"` // 代理 URL(可含用户密码或 socks5)
Host string `yaml:"Host"` // Host
Scheme string `yaml:"Scheme"` // 协议
TLS *SitePluginTLS `yaml:"TLS"` // TLS
TLSHandshakeTimeout int64 `yaml:"TLSHandshakeTimeout"` // 握手超时(毫秒单位)
DisableKeepAlives bool `yaml:"DisableKeepAlives"` // 禁止长连接
DisableCompression bool `yaml:"DisableCompression"` // 禁止压缩
MaxIdleConnsPerHost int `yaml:"MaxIdleConnsPerHost"` // 每个主机最大空闲连接
MaxConnsPerHost int `yaml:"MaxConnsPerHost"` // 每个主机最大连接
IdleConnTimeout int64 `yaml:"IdleConnTimeout"` // 空闲连接超时(毫秒单位)
ResponseHeaderTimeout int64 `yaml:"ResponseHeaderTimeout"` // 请求 Header 超时(毫秒单位)
ExpectContinueTimeout int64 `yaml:"ExpectContinueTimeout"` // 发送 Expect: 100-continue 的 PUT 超时
ProxyConnectHeader http.Header `yaml:"ProxyConnectHeader"` // CONNECT 代理请求额外标头
MaxResponseHeaderBytes int64 `yaml:"MaxResponseHeaderBytes"` // 最大响应标头限制(字节)
ReadBufferSize int `yaml:"ReadBufferSize"` // 读取缓冲大小
WriteBufferSize int `yaml:"WriteBufferSize"` // 写入缓冲大小
ForceAttemptHTTP2 bool `yaml:"ForceAttemptHTTP2"` // 支持 HTTP/2
}
SitePlugin 配置-插件
func (*SitePlugin) ConfigPluginHTTPClient ¶
func (T *SitePlugin) ConfigPluginHTTPClient(c *vweb.PluginHTTPClient) error
func (*SitePlugin) ConfigPluginRPCClient ¶
func (T *SitePlugin) ConfigPluginRPCClient(c *vweb.PluginRPCClient) error
type SitePluginTLS ¶
type SitePluginTLS struct {
ServerName string `yaml:"ServerName"` // 服务器名称
InsecureSkipVerify bool `yaml:"InsecureSkipVerify"` // 跳过证书验证
NextProtos []string `yaml:"NextProtos"` // ALPN 协议,如:http/1.1
CipherSuites []uint16 `yaml:"CipherSuites"` // 密码套件列表
ClientSessionCache int `yaml:"ClientSessionCache"` // TLS 会话恢复 ClientSessionState 缓存大小(Client 端)
CurvePreferences []tls.CurveID `yaml:"CurvePreferences"` // ECDHE 握手曲线偏好(Client 端)
RootCAs []string `yaml:"RootCAs"` // 根证书文件路径列表
}
SitePluginTLS 配置-插件-TLS
type SitePlugins ¶
type SitePlugins struct {
RPC map[string]SitePlugin `yaml:"RPC"`
HTTP map[string]SitePlugin `yaml:"HTTP"`
}
SitePlugins 配置-插件
func (*SitePlugins) ConfigSitePluginHTTP ¶
func (T *SitePlugins) ConfigSitePluginHTTP(origin *SitePlugin, handle HandleFunc) bool
ConfigSitePluginHTTP 从公共 HTTP 配置模板中合并配置到 origin 中
func (*SitePlugins) ConfigSitePluginRPC ¶
func (T *SitePlugins) ConfigSitePluginRPC(origin *SitePlugin, handle HandleFunc) bool
ConfigSitePluginRPC 从公共 RPC 配置模板中合并配置到 origin 中
type SitePublic ¶
type SitePublic struct {
Header map[string]SiteHeader `yaml:"Header"`
Session map[string]SiteSession `yaml:"Session"`
Plugin SitePlugins `yaml:"Plugin"`
Forward map[string]SiteForwards `yaml:"Forward"`
Dynamic map[string]SiteDynamic `yaml:"Dynamic"`
}
SitePublic 公共站点配置
func (*SitePublic) ConfigSiteDynamic ¶
func (T *SitePublic) ConfigSiteDynamic(origin *SiteDynamic, handle HandleFunc) bool
ConfigSiteDynamic 将公共 Dynamic 配置合并到 origin。 规则:以公共配置为底,origin 中非零字段覆盖公共配置,结果写回 origin。 返回 true 表示成功合并;PublicName 为空、未找到或拷贝失败时返回 false。
func (*SitePublic) ConfigSiteForward ¶
func (T *SitePublic) ConfigSiteForward(origin *SiteForwards, handle HandleFunc) bool
ConfigSiteForward 将公共 Forward 列表追加到 origin.List。 与其它 Config* 不同:采用追加语义(公共规则在前或后由调用方 List 初始内容决定), 且不覆盖 origin 已有项。合并时会复制元素并清空运行时字段 forwardWriter,避免共享可变状态。 handle 保留签名以兼容既有调用方;转发列表为切片追加,不走字段级深拷贝过滤。
func (*SitePublic) ConfigSiteHeader ¶
func (T *SitePublic) ConfigSiteHeader(origin *SiteHeader, handle HandleFunc) bool
ConfigSiteHeader 将公共 Header 配置合并到 origin(公共为底,origin 非零字段覆盖)。
func (*SitePublic) ConfigSitePlugin ¶ added in v3.1.0
func (T *SitePublic) ConfigSitePlugin(origin *SitePlugin, name string, handle HandleFunc) bool
ConfigSitePlugin 按 kind("rpc" / "http",大小写不敏感)与 PublicName 合并公共插件配置到 origin。 补全原结构体存在 Plugin 字段却无对应合并入口的功能盲区。 未找到或参数非法时返回 false。
func (*SitePublic) ConfigSiteSession ¶
func (T *SitePublic) ConfigSiteSession(origin *SiteSession, handle HandleFunc) bool
ConfigSiteSession 将公共 Session 配置合并到 origin(公共为底,origin 非零字段覆盖)。
type SiteSession ¶
type SiteSession struct {
// 引用公共配置后,该结构中的字段如果也有设置,将会优先使用。
PublicName string `yaml:"PublicName"` // 引用公共配置的名字
Name string `yaml:"Name"` // 会话名称
Expired int64 `yaml:"Expired"` // 过期时间(秒单位,默认 20 分钟)
Size int `yaml:"Size"` // 会话 ID 长度(默认 64)
Salt string `yaml:"Salt"` // 加盐(伪随机数补充熵,可为空)
}
SiteSession 配置-会话
type Sites ¶
type Sites struct {
Public SitePublic `yaml:"Public"`
Site []Site `yaml:"Site"` // 站点
}
Sites 站点集合