shared

package
v0.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 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

所有的运算符

func DefaultRequestVariables

func DefaultRequestVariables() []maps.Map

DefaultRequestVariables 默认的请求变量列表

Types

type BodyType

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

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 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 校验

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
	// 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

运算符定义

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

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

func (this *TimeDuration) Duration() time.Duration

type TimeDurationUnit

type TimeDurationUnit = string
const (
	TimeDurationUnitMS     TimeDurationUnit = "ms"
	TimeDurationUnitSecond TimeDurationUnit = "second"
	TimeDurationUnitMinute TimeDurationUnit = "minute"
	TimeDurationUnitHour   TimeDurationUnit = "hour"
	TimeDurationUnitDay    TimeDurationUnit = "day"
	TimeDurationUnitWeek   TimeDurationUnit = "week"
)

Jump to

Keyboard shortcuts

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