Documentation ¶
Index ¶
- Variables
- func AllRequestOperators() []maps.Map
- type AccessConfig
- type AccessPolicy
- type CachePolicy
- func (this *CachePolicy) CapacitySize() float64
- func (this *CachePolicy) ContainsCacheControl(value string) bool
- func (this *CachePolicy) Delete() error
- func (this *CachePolicy) LifeDuration() time.Duration
- func (this *CachePolicy) MatchKeyword(keyword string) (matched bool, name string, tags []string)
- func (this *CachePolicy) MaxDataSize() float64
- func (this *CachePolicy) Save() error
- func (this *CachePolicy) Validate() error
- type ClientConfig
- type FileLocker
- type HeaderConfig
- type HeaderList
- func (this *HeaderList) AddIgnoreResponseHeader(name string)
- func (this *HeaderList) AddRequestHeader(header *HeaderConfig)
- func (this *HeaderList) AddResponseHeader(header *HeaderConfig)
- func (this *HeaderList) AllIgnoreResponseHeaders() []string
- func (this *HeaderList) AllRequestHeaders() []*HeaderConfig
- func (this *HeaderList) AllResponseHeaders() []*HeaderConfig
- func (this *HeaderList) ContainsIgnoreResponseHeader(name string) bool
- func (this *HeaderList) ContainsResponseHeader(name string) bool
- func (this *HeaderList) FindRequestHeader(headerId string) *HeaderConfig
- func (this *HeaderList) FindResponseHeader(headerId string) *HeaderConfig
- func (this *HeaderList) HasIgnoreHeaders() bool
- func (this *HeaderList) HasRequestHeaders() bool
- func (this *HeaderList) HasResponseHeaders() bool
- func (this *HeaderList) RemoveIgnoreResponseHeader(name string)
- func (this *HeaderList) RemoveRequestHeader(headerId string)
- func (this *HeaderList) RemoveResponseHeader(headerId string)
- func (this *HeaderList) UpdateIgnoreResponseHeader(oldName string, newName string)
- func (this *HeaderList) UppercaseIgnoreHeaders() []string
- func (this *HeaderList) ValidateHeaders() error
- type HeaderListInterface
- type IPRangeConfig
- type IPRangeType
- type RequestCall
- type RequestCond
- type RequestCondOperator
- type Variable
Constants ¶
This section is empty.
Variables ¶
View Source
var ( RegexpDigitNumber = regexp.MustCompile(`^\d+$`) // 正整数 RegexpFloatNumber = regexp.MustCompile(`^\d+(\.\d+)?$`) // 正浮点数,不支持e RegexpAllDigitNumber = regexp.MustCompile(`^[+-]?\d+$`) // 整数,支持正负数 RegexpAllFloatNumber = regexp.MustCompile(`^[+-]?\d+(\.\d+)?$`) // 浮点数,支持正负数,不支持e RegexpExternalURL = regexp.MustCompile("(?i)^(http|https|ftp)://") // URL RegexpNamedVariable = regexp.MustCompile("\\${[\\w.-]+}") // 命名变量 )
常用的正则表达式
View Source
var DefaultSkippedResponseCacheControlValues = []string{"private", "no-cache", "no-store"}
View Source
var Locker = new(FileLocker)
Functions ¶
Types ¶
type AccessConfig ¶
type AccessConfig struct { On bool `yaml:"on" json:"on"` // 是否开启 AllowOn bool `yaml:"allowOn" json:"allowOn"` // 白名单是否开启 DenyOn bool `yaml:"denyOn" json:"denyOn"` // 黑名单是否开启 Allow []*ClientConfig `yaml:"allow" json:"allow"` // 允许的IP Deny []*ClientConfig `yaml:"deny" json:"deny"` // 禁止的IP }
访问控制
type AccessPolicy ¶
type AccessPolicy struct { // 流量控制 Traffic struct { On bool `yaml:"on" json:"on"` // 是否开启 Total struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"total" json:"total"` // 总量控制 Second struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Duration int64 `yaml:"duration" json:"duration"` // 时间长度 FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间,也是结束时间 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"second" json:"second"` Minute struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Duration int64 `yaml:"duration" json:"duration"` // 时间长度 FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间 ToTime int64 `yaml:"toTime" json:"toTime"` // 结束时间 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"minute" json:"minute"` Hour struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Duration int64 `yaml:"duration" json:"duration"` // 时间长度 FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间 ToTime int64 `yaml:"toTime" json:"toTime"` // 结束时间 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"hour" json:"hour"` Day struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Duration int64 `yaml:"duration" json:"duration"` // 时间长度 FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间 ToTime int64 `yaml:"toTime" json:"toTime"` // 结束时间 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"day" json:"day"` Month struct { On bool `yaml:"on" json:"on"` // 是否开启 Total int64 `yaml:"total" json:"total"` // 总量 Duration int64 `yaml:"duration" json:"duration"` // 时间长度 FromTime int64 `yaml:"fromTime" json:"fromTime"` // 开始时间 ToTime int64 `yaml:"toTime" json:"toTime"` // 结束时间 Used int64 `yaml:"used" json:"used"` // 已使用量 } `yaml:"month" json:"month"` } `yaml:"traffic" json:"traffic"` // 流量控制 // 访问控制 Access AccessConfig `yaml:"access" json:"access"` // 访问控制 // contains filtered or unexported fields }
API控制策略
func (*AccessPolicy) AllowTraffic ¶
func (this *AccessPolicy) AllowTraffic() (reason string, allowed bool)
检查流量
type CachePolicy ¶
type CachePolicy struct { Filename string `yaml:"filename" json:"filename"` // 文件名 Id string `yaml:"id" json:"id"` On bool `yaml:"on" json:"on"` // 是否开启 TODO Name string `yaml:"name" json:"name"` // 名称 Key string `yaml:"key" json:"key"` // 每个缓存的Key规则,里面可以有变量 Capacity string `yaml:"capacity" json:"capacity"` // 最大内容容量 Life string `yaml:"life" json:"life"` // 时间 Status []int `yaml:"status" json:"status"` // 缓存的状态码列表 MaxSize string `yaml:"maxSize" json:"maxSize"` // 能够请求的最大尺寸 SkipResponseCacheControlValues []string `yaml:"skipCacheControlValues" json:"skipCacheControlValues"` // 可以跳过的响应的Cache-Control值 SkipResponseSetCookie bool `yaml:"skipSetCookie" json:"skipSetCookie"` // 是否跳过响应的Set-Cookie Header EnableRequestCachePragma bool `yaml:"enableRequestCachePragma" json:"enableRequestCachePragma"` // 是否支持客户端的Pragma: no-cache Cond []*RequestCond `yaml:"cond" json:"cond"` Type string `yaml:"type" json:"type"` // 类型 Options map[string]interface{} `yaml:"options" json:"options"` // 选项 // contains filtered or unexported fields }
缓存策略配置
func (*CachePolicy) ContainsCacheControl ¶
func (this *CachePolicy) ContainsCacheControl(value string) bool
是否包含某个Cache-Control值
func (*CachePolicy) MatchKeyword ¶
func (this *CachePolicy) MatchKeyword(keyword string) (matched bool, name string, tags []string)
检查是否匹配关键词
type ClientConfig ¶
type ClientConfig struct { Id string `yaml:"id" json:"id"` // ID On bool `yaml:"on" json:"on"` // 是否开启 IP string `yaml:"ip" json:"ip"` // IP Description string `yaml:"description" json:"description"` // 描述 // contains filtered or unexported fields }
客户端配置
type FileLocker ¶
type FileLocker struct {
// contains filtered or unexported fields
}
global file modify locker
func (*FileLocker) WriteUnlockNotify ¶
func (this *FileLocker) WriteUnlockNotify()
unlock for write and notify
type HeaderConfig ¶
type HeaderConfig struct { On bool `yaml:"on" json:"on"` // 是否开启 Id string `yaml:"id" json:"id"` // ID Name string `yaml:"name" json:"name"` // Name Value string `yaml:"value" json:"value"` // Value Always bool `yaml:"always" json:"always"` // 是否忽略状态码 Status []int `yaml:"status" json:"status"` // 支持的状态码 // contains filtered or unexported fields }
头部信息定义
type HeaderList ¶
type HeaderList struct { // 添加的响应Headers Headers []*HeaderConfig `yaml:"headers" json:"headers"` // 忽略的响应Headers IgnoreHeaders []string `yaml:"ignoreHeaders" json:"ignoreHeaders"` // 自定义请求Headers RequestHeaders []*HeaderConfig `yaml:"requestHeaders" json:"requestHeaders"` // contains filtered or unexported fields }
HeaderList定义
func (*HeaderList) AddIgnoreResponseHeader ¶
func (this *HeaderList) AddIgnoreResponseHeader(name string)
添加IgnoreHeader
func (*HeaderList) AddRequestHeader ¶
func (this *HeaderList) AddRequestHeader(header *HeaderConfig)
添加请求Header
func (*HeaderList) AddResponseHeader ¶
func (this *HeaderList) AddResponseHeader(header *HeaderConfig)
添加Header
func (*HeaderList) AllIgnoreResponseHeaders ¶
func (this *HeaderList) AllIgnoreResponseHeaders() []string
取得所有的IgnoreHeader
func (*HeaderList) AllRequestHeaders ¶
func (this *HeaderList) AllRequestHeaders() []*HeaderConfig
取得所有的请求Header
func (*HeaderList) AllResponseHeaders ¶
func (this *HeaderList) AllResponseHeaders() []*HeaderConfig
取得所有的Header
func (*HeaderList) ContainsIgnoreResponseHeader ¶
func (this *HeaderList) ContainsIgnoreResponseHeader(name string) bool
判断是否包含IgnoreHeader
func (*HeaderList) ContainsResponseHeader ¶
func (this *HeaderList) ContainsResponseHeader(name string) bool
判断是否包含Header
func (*HeaderList) FindRequestHeader ¶
func (this *HeaderList) FindRequestHeader(headerId string) *HeaderConfig
查找请求Header
func (*HeaderList) FindResponseHeader ¶
func (this *HeaderList) FindResponseHeader(headerId string) *HeaderConfig
查找Header
func (*HeaderList) HasIgnoreHeaders ¶
func (this *HeaderList) HasIgnoreHeaders() bool
判断是否有Ignore Headers
func (*HeaderList) HasRequestHeaders ¶
func (this *HeaderList) HasRequestHeaders() bool
判断是否有请求Header
func (*HeaderList) HasResponseHeaders ¶
func (this *HeaderList) HasResponseHeaders() bool
是否有Headers
func (*HeaderList) RemoveIgnoreResponseHeader ¶
func (this *HeaderList) RemoveIgnoreResponseHeader(name string)
移除IgnoreHeader
func (*HeaderList) RemoveRequestHeader ¶
func (this *HeaderList) RemoveRequestHeader(headerId string)
移除请求Header
func (*HeaderList) RemoveResponseHeader ¶
func (this *HeaderList) RemoveResponseHeader(headerId string)
移除Header
func (*HeaderList) UpdateIgnoreResponseHeader ¶
func (this *HeaderList) UpdateIgnoreResponseHeader(oldName string, newName string)
修改IgnoreHeader
func (*HeaderList) UppercaseIgnoreHeaders ¶
func (this *HeaderList) UppercaseIgnoreHeaders() []string
查找大写的Ignore Headers
type HeaderListInterface ¶
type HeaderListInterface interface { // 校验 ValidateHeaders() error // 取得所有的IgnoreHeader AllIgnoreResponseHeaders() []string // 添加IgnoreHeader AddIgnoreResponseHeader(name string) // 判断是否包含IgnoreHeader ContainsIgnoreResponseHeader(name string) bool // 移除IgnoreHeader RemoveIgnoreResponseHeader(name string) // 修改IgnoreHeader UpdateIgnoreResponseHeader(oldName string, newName string) // 取得所有的Header AllResponseHeaders() []*HeaderConfig // 添加Header AddResponseHeader(header *HeaderConfig) // 判断是否包含Header ContainsResponseHeader(name string) bool // 查找Header FindResponseHeader(headerId string) *HeaderConfig // 移除Header RemoveResponseHeader(headerId string) // 取得所有的请求Header AllRequestHeaders() []*HeaderConfig // 添加请求Header AddRequestHeader(header *HeaderConfig) // 查找请求Header FindRequestHeader(headerId string) *HeaderConfig // 移除请求Header RemoveRequestHeader(headerId string) }
HeaderList相关操作接口
type IPRangeConfig ¶
type IPRangeConfig struct { Id string `yaml:"id" json:"id"` Type IPRangeType `yaml:"type" json:"type"` Param string `yaml:"param" json:"param"` CIDR string `yaml:"cidr" json:"cidr"` IPFrom string `yaml:"ipFrom" json:"ipFrom"` IPTo string `yaml:"ipTo" json:"ipTo"` // contains filtered or unexported fields }
IP Range
type IPRangeType ¶
type IPRangeType = int
IP Range类型
const ( IPRangeTypeRange IPRangeType = 1 IPRangeTypeCIDR IPRangeType = 2 IPRangeTypeAll IPRangeType = 3 IPRangeTypeWildcard IPRangeType = 4 // 通配符,可以使用* )
type RequestCall ¶
type RequestCall struct { Formatter func(source string) string Request *http.Request ResponseCallbacks []func(resp http.ResponseWriter) Options maps.Map }
请求调用
func (*RequestCall) AddResponseCall ¶
func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter))
添加响应回调
func (*RequestCall) CallResponseCallbacks ¶
func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter)
执行响应回调
type RequestCond ¶
type RequestCond struct { Id string `yaml:"id" json:"id"` // ID // 要测试的字符串 // 其中可以使用跟请求相关的参数,比如: // ${arg.name}, ${requestPath} Param string `yaml:"param" json:"param"` // 运算符 Operator RequestCondOperator `yaml:"operator" json:"operator"` // 对比 Value string `yaml:"value" json:"value"` // contains filtered or unexported fields }
重写条件定义
func (*RequestCond) Match ¶
func (this *RequestCond) Match(formatter func(source string) string) bool
将此条件应用于请求,检查是否匹配
type RequestCondOperator ¶
type RequestCondOperator = string
运算符定义
const ( // 正则 RequestCondOperatorRegexp RequestCondOperator = "regexp" RequestCondOperatorNotRegexp RequestCondOperator = "not regexp" // 数字相关 RequestCondOperatorEqInt RequestCondOperator = "eq int" // 整数等于 RequestCondOperatorEqFloat RequestCondOperator = "eq float" // 浮点数等于 RequestCondOperatorGtFloat RequestCondOperator = "gt" RequestCondOperatorGteFloat RequestCondOperator = "gte" RequestCondOperatorLtFloat RequestCondOperator = "lt" RequestCondOperatorLteFloat RequestCondOperator = "lte" // 取模 RequestCondOperatorMod10 RequestCondOperator = "mod 10" RequestCondOperatorMod100 RequestCondOperator = "mod 100" RequestCondOperatorMod RequestCondOperator = "mod" // 字符串相关 RequestCondOperatorEqString RequestCondOperator = "eq" RequestCondOperatorNeqString RequestCondOperator = "not" RequestCondOperatorHasPrefix RequestCondOperator = "prefix" RequestCondOperatorHasSuffix RequestCondOperator = "suffix" RequestCondOperatorContainsString RequestCondOperator = "contains" RequestCondOperatorNotContainsString RequestCondOperator = "not contains" RequestCondOperatorIn RequestCondOperator = "in" RequestCondOperatorNotIn RequestCondOperator = "not in" RequestCondOperatorFileExt RequestCondOperator = "file ext" RequestCondOperatorFileMimeType RequestCondOperator = "mime type" RequestCondOperatorVersionRange RequestCondOperator = "version range" // IP相关 RequestCondOperatorEqIP RequestCondOperator = "eq ip" RequestCondOperatorGtIP RequestCondOperator = "gt ip" RequestCondOperatorGteIP RequestCondOperator = "gte ip" RequestCondOperatorLtIP RequestCondOperator = "lt ip" RequestCondOperatorLteIP RequestCondOperator = "lte ip" RequestCondOperatorIPRange RequestCondOperator = "ip range" RequestCondOperatorIPMod10 RequestCondOperator = "ip mod 10" RequestCondOperatorIPMod100 RequestCondOperator = "ip mod 100" RequestCondOperatorIPMod RequestCondOperator = "ip mod" // 文件相关 RequestCondOperatorFileExist RequestCondOperator = "file exist" RequestCondOperatorFileNotExist RequestCondOperator = "file not exist" )
Click to show internal directories.
Click to hide internal directories.