Documentation ¶
Index ¶
- Variables
- func AllRequestOperators() []maps.Map
- func DefaultRequestVariables() []maps.Map
- type BodyType
- type DataMap
- type Definition
- type FileLocker
- type Formatter
- type HTTPCORSHeaderConfig
- type HTTPExpireHeaderConfig
- type HTTPHeaderConfig
- type HTTPHeaderPolicy
- type HTTPHeaderPolicyRef
- type HTTPHeaderRef
- type HTTPHeaderReplaceValue
- type HTTPRequestCond
- type HTTPRequestCondGroup
- func (this *HTTPRequestCondGroup) HasRequestConds() bool
- func (this *HTTPRequestCondGroup) HasResponseConds() bool
- func (this *HTTPRequestCondGroup) Init() error
- func (this *HTTPRequestCondGroup) MatchRequest(formatter func(source string) string) bool
- func (this *HTTPRequestCondGroup) MatchResponse(formatter func(source string) string) bool
- type HTTPRequestCondsConfig
- func (this *HTTPRequestCondsConfig) HasRequestConds() bool
- func (this *HTTPRequestCondsConfig) HasResponseConds() bool
- func (this *HTTPRequestCondsConfig) Init() error
- func (this *HTTPRequestCondsConfig) MatchRequest(formatter Formatter) bool
- func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) string) bool
- type HTTPStatusConfig
- type IPRangeConfig
- type IPRangeType
- type MimeTypeRule
- type RequestCall
- type RequestCondOperator
- type SizeCapacity
- type SizeCapacityUnit
- type TimeDuration
- type TimeDurationUnit
- type URLPattern
- type URLPatternType
Constants ¶
This section is empty.
Variables ¶
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.-]+}") // 命名变量 )
常用的正则表达式
var Locker = new(FileLocker)
Functions ¶
func DefaultRequestVariables ¶
DefaultRequestVariables 默认的请求变量列表
Types ¶
type DataMap ¶ added in v1.0.0
DataMap 二进制数据共享Map 用来减少相同数据占用的空间和内存
type Definition ¶
type Definition struct { Name string `json:"name"` Code string `json:"code"` Description string `json:"description"` Icon string `json:"icon"` }
Definition 数据定义
func FindAllBodyTypes ¶
func FindAllBodyTypes() []*Definition
type FileLocker ¶
type FileLocker struct {
// contains filtered or unexported fields
}
global file modify locker
func (*FileLocker) Unlock ¶
func (this *FileLocker) Unlock()
type HTTPCORSHeaderConfig ¶ added in v0.6.0
type HTTPCORSHeaderConfig struct { IsOn bool `yaml:"isOn" json:"isOn"` AllowMethods []string `yaml:"allowMethods" json:"allowMethods"` AllowOrigin string `yaml:"allowOrigin" json:"allowOrigin"` // TODO AllowCredentials bool `yaml:"allowCredentials" json:"allowCredentials"` // TODO,实现时需要升级以往的老数据 ExposeHeaders []string `yaml:"exposeHeaders" json:"exposeHeaders"` MaxAge int32 `yaml:"maxAge" json:"maxAge"` RequestHeaders []string `yaml:"requestHeaders" json:"requestHeaders"` // TODO RequestMethod string `yaml:"requestMethod" json:"requestMethod"` OptionsMethodOnly bool `yaml:"optionsMethodOnly" json:"optionsMethodOnly"` // 是否仅支持OPTIONS方法 }
HTTPCORSHeaderConfig 参考 https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS
func NewHTTPCORSHeaderConfig ¶ added in v1.1.0
func NewHTTPCORSHeaderConfig() *HTTPCORSHeaderConfig
func (*HTTPCORSHeaderConfig) Init ¶ added in v0.6.0
func (this *HTTPCORSHeaderConfig) Init() error
type HTTPHeaderConfig ¶
type HTTPHeaderConfig struct { Id int64 `yaml:"id" json:"id"` // ID IsOn bool `yaml:"isOn" json:"isOn"` // 是否开启 Name string `yaml:"name" json:"name"` // Name Value string `yaml:"value" json:"value"` // Value Status *HTTPStatusConfig `yaml:"status" json:"status"` // 支持的状态码 DisableRedirect bool `yaml:"disableRedirect" json:"disableRedirect"` // 在跳转时不调用 ShouldAppend bool `yaml:"shouldAppend" json:"shouldAppend"` // 是否为附加 ShouldReplace bool `yaml:"shouldReplace" json:"shouldReplace"` // 是否替换值 ReplaceValues []*HTTPHeaderReplaceValue `yaml:"replaceValues" json:"replaceValues"` // 替换值 Methods []string `yaml:"methods" json:"methods"` // 请求方法 Domains []string `yaml:"domains" json:"domains"` // 专属域名 // contains filtered or unexported fields }
HTTPHeaderConfig 头部信息定义
func (*HTTPHeaderConfig) HasVariables ¶
func (this *HTTPHeaderConfig) HasVariables() bool
HasVariables 是否有变量
func (*HTTPHeaderConfig) Match ¶ added in v0.6.4
func (this *HTTPHeaderConfig) Match(statusCode int) bool
Match 判断是否匹配状态码
type HTTPHeaderPolicy ¶
type HTTPHeaderPolicy struct { Id int64 `yaml:"id" json:"id"` // ID Name string `yaml:"name" json:"name"` // 名称 TODO IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 TODO Description string `yaml:"description" json:"description"` // 描述 TODO SetHeaderRefs []*HTTPHeaderRef `yaml:"setHeaderRefs" json:"setHeaderRefs"` SetHeaders []*HTTPHeaderConfig `yaml:"setHeaders" json:"setHeaders"` DeleteHeaders []string `yaml:"deleteHeaders" json:"deleteHeaders"` // 删除的Header Expires *HTTPExpireHeaderConfig `yaml:"expires" json:"expires"` // 内容过期设置 TODO CORS *HTTPCORSHeaderConfig `yaml:"cors" json:"cors"` // CORS跨域设置 NonStandardHeaders []string `yaml:"nonStandardHeaders" json:"nonStandardHeaders"` // 非标Header列表 // contains filtered or unexported fields }
HTTPHeaderPolicy HeaderList定义
func (*HTTPHeaderPolicy) ContainsDeletedHeader ¶
func (this *HTTPHeaderPolicy) ContainsDeletedHeader(name string) bool
ContainsDeletedHeader 判断删除列表中是否包含某个Header
func (*HTTPHeaderPolicy) ContainsHeader ¶
func (this *HTTPHeaderPolicy) ContainsHeader(name string) bool
ContainsHeader 判断Add和Set中是否包含某个Header
type HTTPHeaderPolicyRef ¶
type HTTPHeaderPolicyRef struct { IsPrior bool `yaml:"isPrior" json:"isPrior"` IsOn bool `yaml:"isOn" json:"isOn"` HeaderPolicyId int64 `yaml:"headerPolicyId" json:"headerPolicyId"` }
func (*HTTPHeaderPolicyRef) Init ¶
func (this *HTTPHeaderPolicyRef) Init() error
type HTTPHeaderRef ¶
type HTTPHeaderRef struct { IsOn bool `yaml:"isOn" json:"isOn"` HeaderId int64 `yaml:"headerId" json:"headerId"` }
Header引用
type HTTPHeaderReplaceValue ¶
type HTTPHeaderReplaceValue struct { Pattern string `yaml:"pattern" json:"pattern"` Replacement string `yaml:"replacement" json:"replacement"` IsCaseInsensitive bool `yaml:"isCaseInsensitive" json:"isCaseInsensitive"` // TODO IsRegexp bool `yaml:"isRegexp" json:"isRegexp"` // TODO // contains filtered or unexported fields }
HTTPHeaderReplaceValue 值替换定义
func (*HTTPHeaderReplaceValue) Init ¶
func (this *HTTPHeaderReplaceValue) Init() error
func (*HTTPHeaderReplaceValue) Replace ¶
func (this *HTTPHeaderReplaceValue) Replace(value string) string
type HTTPRequestCond ¶
type HTTPRequestCond struct { Type string `yaml:"type" json:"type"` // 类型,在特殊条件时使用 IsRequest bool `yaml:"isRequest" json:"isRequest"` // 是否为请求的条件,用来区分在什么阶段执行 // 要测试的字符串 // 其中可以使用跟请求相关的参数,比如: // ${arg.name}, ${requestPath} Param string `yaml:"param" json:"param"` Operator RequestCondOperator `yaml:"operator" json:"operator"` // 运算符 Value string `yaml:"value" json:"value"` // 对比值 IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配 IsCaseInsensitive bool `yaml:"isCaseInsensitive" json:"isCaseInsensitive"` // 大小写是否敏感 // contains filtered or unexported fields }
HTTPRequestCond HTTP请求匹配条件定义
func (*HTTPRequestCond) Match ¶
func (this *HTTPRequestCond) Match(formatter func(source string) string) bool
Match 将此条件应用于请求,检查是否匹配
type HTTPRequestCondGroup ¶
type HTTPRequestCondGroup struct { IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用 Connector string `yaml:"connector" json:"connector"` // 条件之间的关系 Conds []*HTTPRequestCond `yaml:"conds" json:"conds"` // 条件列表 IsReverse bool `yaml:"isReverse" json:"isReverse"` // 是否反向匹配 Description string `yaml:"description" json:"description"` // 说明 // contains filtered or unexported fields }
HTTPRequestCondGroup 请求条件分组
func (*HTTPRequestCondGroup) HasRequestConds ¶
func (this *HTTPRequestCondGroup) HasRequestConds() bool
func (*HTTPRequestCondGroup) HasResponseConds ¶
func (this *HTTPRequestCondGroup) HasResponseConds() bool
func (*HTTPRequestCondGroup) MatchRequest ¶
func (this *HTTPRequestCondGroup) MatchRequest(formatter func(source string) string) bool
func (*HTTPRequestCondGroup) MatchResponse ¶
func (this *HTTPRequestCondGroup) MatchResponse(formatter func(source string) string) bool
type HTTPRequestCondsConfig ¶
type HTTPRequestCondsConfig struct { IsOn bool `yaml:"isOn" json:"isOn"` Connector string `yaml:"connector" json:"connector"` Groups []*HTTPRequestCondGroup `yaml:"groups" json:"groups"` // contains filtered or unexported fields }
HTTPRequestCondsConfig 条件配置 数据结构:conds -> []groups -> []cond
func (*HTTPRequestCondsConfig) HasRequestConds ¶
func (this *HTTPRequestCondsConfig) HasRequestConds() bool
HasRequestConds 判断是否有请求条件
func (*HTTPRequestCondsConfig) HasResponseConds ¶
func (this *HTTPRequestCondsConfig) HasResponseConds() bool
HasResponseConds 判断是否有响应条件
func (*HTTPRequestCondsConfig) MatchRequest ¶
func (this *HTTPRequestCondsConfig) MatchRequest(formatter Formatter) bool
MatchRequest 判断请求是否匹配
func (*HTTPRequestCondsConfig) MatchResponse ¶
func (this *HTTPRequestCondsConfig) MatchResponse(formatter func(s string) string) bool
MatchResponse 判断响应是否匹配
type HTTPStatusConfig ¶
type HTTPStatusConfig struct { Always bool `yaml:"always" json:"always"` Codes []int `yaml:"codes" json:"codes"` }
HTTPStatusConfig 状态码
func (*HTTPStatusConfig) Init ¶
func (this *HTTPStatusConfig) Init() error
func (*HTTPStatusConfig) Match ¶
func (this *HTTPStatusConfig) Match(statusCode int) bool
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 }
IPRangeConfig IP Range
func (*IPRangeConfig) Contains ¶
func (this *IPRangeConfig) Contains(ipString string) bool
Contains 是否包含某个IP
type IPRangeType ¶
type IPRangeType = int
IPRangeType IP Range类型
const ( IPRangeTypeRange IPRangeType = 1 IPRangeTypeCIDR IPRangeType = 2 IPRangeTypeAll IPRangeType = 3 IPRangeTypeWildcard IPRangeType = 4 // 通配符,可以使用* )
type MimeTypeRule ¶
type MimeTypeRule struct { Value string // contains filtered or unexported fields }
MimeTypeRule mime type规则
func NewMimeTypeRule ¶
func NewMimeTypeRule(mimeType string) (*MimeTypeRule, error)
func (*MimeTypeRule) Match ¶
func (this *MimeTypeRule) Match(mimeType string) bool
type RequestCall ¶
type RequestCall struct { Formatter func(source string) string // 当前变量格式化函数 Request *http.Request // 当前请求 Domain string // 当前域名 ResponseCallbacks []func(resp http.ResponseWriter) Options maps.Map }
RequestCall 请求调用
func (*RequestCall) AddResponseCall ¶
func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter))
AddResponseCall 添加响应回调
func (*RequestCall) CallResponseCallbacks ¶
func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter)
CallResponseCallbacks 执行响应回调
type RequestCondOperator ¶
type RequestCondOperator = string
RequestCondOperator 运算符定义
const ( RequestCondOperatorRegexp RequestCondOperator = "regexp" RequestCondOperatorNotRegexp RequestCondOperator = "not regexp" RequestCondOperatorWildcardMatch RequestCondOperator = "wildcard match" RequestCondOperatorWildcardNotMatch RequestCondOperator = "wildcard not match" 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" 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" )
type SizeCapacity ¶
type SizeCapacity struct { Count int64 `json:"count" yaml:"count"` Unit SizeCapacityUnit `json:"unit" yaml:"unit"` }
func DecodeSizeCapacityJSON ¶
func DecodeSizeCapacityJSON(sizeCapacityJSON []byte) (*SizeCapacity, error)
func NewSizeCapacity ¶
func NewSizeCapacity(count int64, unit SizeCapacityUnit) *SizeCapacity
func (*SizeCapacity) AsJSON ¶
func (this *SizeCapacity) AsJSON() ([]byte, error)
func (*SizeCapacity) Bytes ¶
func (this *SizeCapacity) Bytes() int64
func (*SizeCapacity) IsNotEmpty ¶
func (this *SizeCapacity) IsNotEmpty() bool
type SizeCapacityUnit ¶
type SizeCapacityUnit = string
const ( SizeCapacityUnitByte SizeCapacityUnit = "byte" SizeCapacityUnitKB SizeCapacityUnit = "kb" SizeCapacityUnitMB SizeCapacityUnit = "mb" SizeCapacityUnitGB SizeCapacityUnit = "gb" SizeCapacityUnitTB SizeCapacityUnit = "tb" SizeCapacityUnitPB SizeCapacityUnit = "pb" SizeCapacityUnitEB SizeCapacityUnit = "eb" )
type TimeDuration ¶
type TimeDuration struct { Count int64 `yaml:"count" json:"count"` // 数量 Unit TimeDurationUnit `yaml:"unit" json:"unit"` // 单位 }
TimeDuration 时间间隔
func (*TimeDuration) AsJSON ¶
func (this *TimeDuration) AsJSON() ([]byte, error)
func (*TimeDuration) Description ¶ added in v1.1.0
func (this *TimeDuration) Description() string
func (*TimeDuration) Duration ¶
func (this *TimeDuration) Duration() time.Duration
func (*TimeDuration) Seconds ¶ added in v1.1.0
func (this *TimeDuration) Seconds() int64
type TimeDurationUnit ¶
type TimeDurationUnit = string
const ( TimeDurationUnitMS TimeDurationUnit = "ms" TimeDurationUnitSecond TimeDurationUnit = "second" TimeDurationUnitMinute TimeDurationUnit = "minute" TimeDurationUnitHour TimeDurationUnit = "hour" TimeDurationUnitDay TimeDurationUnit = "day" TimeDurationUnitWeek TimeDurationUnit = "week" )
type URLPattern ¶ added in v0.6.4
type URLPattern struct { Type URLPatternType `yaml:"type" json:"type"` Pattern string `yaml:"pattern" json:"pattern"` // contains filtered or unexported fields }
func (*URLPattern) Init ¶ added in v0.6.4
func (this *URLPattern) Init() error
func (*URLPattern) Match ¶ added in v0.6.4
func (this *URLPattern) Match(url string) bool
type URLPatternType ¶ added in v0.6.4
type URLPatternType = string
const ( URLPatternTypeWildcard URLPatternType = "wildcard" // 通配符 URLPatternTypeRegexp URLPatternType = "regexp" // 正则表达式 )
Source Files ¶
- body_type.go
- data_map.go
- definition.go
- formatter.go
- http_cors_header_config.go
- http_expire_header_config.go
- http_header_config.go
- http_header_policy.go
- http_header_policy_ref.go
- http_header_ref.go
- http_request_cond.go
- http_request_cond_group.go
- http_request_conds_config.go
- http_status_config.go
- ip_range.go
- locker.go
- mime_type_rule.go
- regexp.go
- request_call.go
- request_operators.go
- request_variables.go
- size_capacity.go
- time_duration.go
- url_pattern.go