Documentation ¶
Index ¶
- Variables
- 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 Pair
- type RequestCall
- type Variable
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultSkippedResponseCacheControlValues = []string{"private", "no-cache", "no-store"}
View Source
var Locker = new(FileLocker)
Functions ¶
This section is empty.
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 Type string `yaml:"type" json:"type"` // 类型 Options map[string]interface{} `yaml:"options" json:"options"` // 选项 // contains filtered or unexported fields }
缓存策略配置
func (*CachePolicy) ContainsCacheControl ¶ added in v0.1.5
func (this *CachePolicy) ContainsCacheControl(value string) bool
是否包含某个Cache-Control值
func (*CachePolicy) MatchKeyword ¶ added in v0.1.7
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 ¶ added in v0.1.4
type FileLocker struct {
// contains filtered or unexported fields
}
global file modify locker
func (*FileLocker) ReadUnlock ¶ added in v0.1.4
func (this *FileLocker) ReadUnlock()
unlock for read
func (*FileLocker) WriteUnlock ¶ added in v0.1.4
func (this *FileLocker) WriteUnlock()
unlock for write
func (*FileLocker) WriteUnlockNotify ¶ added in v0.1.4
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 }
头部信息定义
func (*HeaderConfig) HasVariables ¶ added in v0.1.5
func (this *HeaderConfig) HasVariables() bool
是否有变量
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 ¶ added in v0.1.5
func (this *HeaderList) AddIgnoreResponseHeader(name string)
添加IgnoreHeader
func (*HeaderList) AddRequestHeader ¶ added in v0.1.5
func (this *HeaderList) AddRequestHeader(header *HeaderConfig)
添加请求Header
func (*HeaderList) AddResponseHeader ¶ added in v0.1.5
func (this *HeaderList) AddResponseHeader(header *HeaderConfig)
添加Header
func (*HeaderList) AllIgnoreResponseHeaders ¶ added in v0.1.5
func (this *HeaderList) AllIgnoreResponseHeaders() []string
取得所有的IgnoreHeader
func (*HeaderList) AllRequestHeaders ¶ added in v0.1.5
func (this *HeaderList) AllRequestHeaders() []*HeaderConfig
取得所有的请求Header
func (*HeaderList) AllResponseHeaders ¶ added in v0.1.5
func (this *HeaderList) AllResponseHeaders() []*HeaderConfig
取得所有的Header
func (*HeaderList) ContainsIgnoreResponseHeader ¶ added in v0.1.5
func (this *HeaderList) ContainsIgnoreResponseHeader(name string) bool
判断是否包含IgnoreHeader
func (*HeaderList) ContainsResponseHeader ¶ added in v0.1.5
func (this *HeaderList) ContainsResponseHeader(name string) bool
判断是否包含Header
func (*HeaderList) FindRequestHeader ¶ added in v0.1.5
func (this *HeaderList) FindRequestHeader(headerId string) *HeaderConfig
查找请求Header
func (*HeaderList) FindResponseHeader ¶ added in v0.1.5
func (this *HeaderList) FindResponseHeader(headerId string) *HeaderConfig
查找Header
func (*HeaderList) HasIgnoreHeaders ¶ added in v0.1.6
func (this *HeaderList) HasIgnoreHeaders() bool
判断是否有Ignore Headers
func (*HeaderList) HasRequestHeaders ¶ added in v0.1.5
func (this *HeaderList) HasRequestHeaders() bool
判断是否有请求Header
func (*HeaderList) HasResponseHeaders ¶ added in v0.1.5
func (this *HeaderList) HasResponseHeaders() bool
是否有Headers
func (*HeaderList) RemoveIgnoreResponseHeader ¶ added in v0.1.5
func (this *HeaderList) RemoveIgnoreResponseHeader(name string)
移除IgnoreHeader
func (*HeaderList) RemoveRequestHeader ¶ added in v0.1.5
func (this *HeaderList) RemoveRequestHeader(headerId string)
移除请求Header
func (*HeaderList) RemoveResponseHeader ¶ added in v0.1.5
func (this *HeaderList) RemoveResponseHeader(headerId string)
移除Header
func (*HeaderList) UpdateIgnoreResponseHeader ¶ added in v0.1.5
func (this *HeaderList) UpdateIgnoreResponseHeader(oldName string, newName string)
修改IgnoreHeader
func (*HeaderList) UppercaseIgnoreHeaders ¶ added in v0.1.6
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 Pair ¶ added in v0.1.2
type Pair struct { Name string `yaml:"name" json:"name"` // 变量名 Value string `yaml:"value" json:"value"` // 变量值 }
键值对
type RequestCall ¶ added in v0.1.2
type RequestCall struct { Formatter func(source string) string Request *http.Request ResponseCallbacks []func(resp http.ResponseWriter) Options maps.Map }
请求调用
func (*RequestCall) AddResponseCall ¶ added in v0.1.2
func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter))
添加响应回调
func (*RequestCall) CallResponseCallbacks ¶ added in v0.1.2
func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter)
执行响应回调
Click to show internal directories.
Click to hide internal directories.