shared

package
v1.3.8 Latest Latest
Warning

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

Go to latest
Published: May 1, 2024 License: BSD-3-Clause Imports: 18 Imported by: 1

Documentation

Index

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 Locker = new(FileLocker)

Functions

func AllRequestOperators

func AllRequestOperators() []maps.Map

AllRequestOperators 所有的运算符

func DefaultRequestVariables

func DefaultRequestVariables() []maps.Map

DefaultRequestVariables 默认的请求变量列表

Types

type BitSizeCapacity added in v1.3.3

type BitSizeCapacity struct {
	Count int64               `json:"count" yaml:"count"`
	Unit  BitSizeCapacityUnit `json:"unit" yaml:"unit"`
}

func DecodeBitSizeCapacityJSON added in v1.3.3

func DecodeBitSizeCapacityJSON(sizeCapacityJSON []byte) (*BitSizeCapacity, error)

func NewBitSizeCapacity added in v1.3.3

func NewBitSizeCapacity(count int64, unit BitSizeCapacityUnit) *BitSizeCapacity

func (*BitSizeCapacity) AsJSON added in v1.3.3

func (this *BitSizeCapacity) AsJSON() ([]byte, error)

func (*BitSizeCapacity) Bits added in v1.3.3

func (this *BitSizeCapacity) Bits() int64

func (*BitSizeCapacity) IsNotEmpty added in v1.3.3

func (this *BitSizeCapacity) IsNotEmpty() bool

type BitSizeCapacityUnit added in v1.3.3

type BitSizeCapacityUnit = string
const (
	BitSizeCapacityUnitB  BitSizeCapacityUnit = "b"
	BitSizeCapacityUnitKB BitSizeCapacityUnit = "kb"
	BitSizeCapacityUnitMB BitSizeCapacityUnit = "mb"
	BitSizeCapacityUnitGB BitSizeCapacityUnit = "gb"
	BitSizeCapacityUnitTB BitSizeCapacityUnit = "tb"
	BitSizeCapacityUnitPB BitSizeCapacityUnit = "pb"
	BitSizeCapacityUnitEB BitSizeCapacityUnit = "eb"
)

type BodyType

type BodyType = string
const (
	BodyTypeURL  BodyType = "url"
	BodyTypeHTML BodyType = "html"
)

type DataMap added in v1.0.0

type DataMap struct {
	Map map[string][]byte
	// contains filtered or unexported fields
}

DataMap 二进制数据共享Map 用来减少相同数据占用的空间和内存

func NewDataMap added in v1.0.0

func NewDataMap() *DataMap

NewDataMap 构建对象

func (*DataMap) Put added in v1.0.0

func (this *DataMap) Put(data []byte) (keyData []byte)

Put 放入数据

func (*DataMap) Read added in v1.0.0

func (this *DataMap) Read(key []byte) []byte

Read 读取数据

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

func (this *FileLocker) Lock()

lock

func (*FileLocker) Unlock

func (this *FileLocker) Unlock()

type Formatter

type Formatter = func(s string) string

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 HTTPExpireHeaderConfig

type HTTPExpireHeaderConfig struct {
}

HTTP Header中Expire设置

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 NewHeaderConfig

func NewHeaderConfig() *HTTPHeaderConfig

NewHeaderConfig 获取新Header对象

func (*HTTPHeaderConfig) HasVariables

func (this *HTTPHeaderConfig) HasVariables() bool

HasVariables 是否有变量

func (*HTTPHeaderConfig) Init

func (this *HTTPHeaderConfig) Init() error

Init 校验

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

func (*HTTPHeaderPolicy) Init

func (this *HTTPHeaderPolicy) Init() error

Init 校验

func (*HTTPHeaderPolicy) IsEmpty

func (this *HTTPHeaderPolicy) IsEmpty() bool

IsEmpty 判断是否为空

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

func (this *HTTPRequestCond) Init() error

Init 校验配置

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

func (this *HTTPRequestCondGroup) Init() error

Init 初始化

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

func (this *HTTPRequestCondsConfig) Init() error

Init 初始化

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 NewIPRangeConfig

func NewIPRangeConfig() *IPRangeConfig

NewIPRangeConfig 获取新对象

func ParseIPRange

func ParseIPRange(s string) (*IPRangeConfig, error)

ParseIPRange 从字符串中分析

func (*IPRangeConfig) Contains

func (this *IPRangeConfig) Contains(ipString string) bool

Contains 是否包含某个IP

func (*IPRangeConfig) Init

func (this *IPRangeConfig) Init() error

Init 初始化校验

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 NewRequestCall

func NewRequestCall() *RequestCall

NewRequestCall 获取新对象

func (*RequestCall) AddResponseCall

func (this *RequestCall) AddResponseCall(callback func(resp http.ResponseWriter))

AddResponseCall 添加响应回调

func (*RequestCall) CallResponseCallbacks

func (this *RequestCall) CallResponseCallbacks(resp http.ResponseWriter)

CallResponseCallbacks 执行响应回调

func (*RequestCall) Reset

func (this *RequestCall) Reset()

Reset 重置

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"   // 正则表达式
	URLPatternTypeImages   URLPatternType = "images"   // 常见图片
	URLPatternTypeAudios   URLPatternType = "audios"   // 常见音频
	URLPatternTypeVideos   URLPatternType = "videos"   // 常见视频
)

Jump to

Keyboard shortcuts

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