bfe_expr

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 23 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const HashBucketSize = 10000

HashBucketSize 哈希桶空间,与旧条件原语 *_hash_in 保持一致

View Source
const HashMatcherBucketSize = 10000

HashMatcherBucketSize 旧哈希原语的桶空间

Variables

This section is empty.

Functions

func EvalParams

func EvalParams(req *bfe_basic.Request, params []*Param) []string

EvalParams 运行期批量求值。单个参数求值失败 → 置空 + warn,继续执行; 数据缺失返回 ""(Env 约定,非错误)。

func ValidateLegacyArgs

func ValidateLegacyArgs(src string) error

ValidateLegacyArgs 校验条件串中旧原语字面量参数(正则/哈希区间/时间格式), 使旧实现"加载期拒绝非法配置"的行为在新引擎下保持等价

Types

type BaseEnv

type BaseEnv struct {
	// contains filtered or unexported fields
}

func (*BaseEnv) BackendAddr

func (e *BaseEnv) BackendAddr() string

func (*BaseEnv) BackendPort

func (e *BaseEnv) BackendPort() int

func (*BaseEnv) Env

func (e *BaseEnv) Env(name string) string

Env 读取进程环境变量,不存在返回 ""

func (*BaseEnv) LogInfo

func (e *BaseEnv) LogInfo(msg string) bool

LogInfo 输出 info 日志(附带 logid),返回 true 便于嵌入条件表达式(cond && LogInfo(...))

func (*BaseEnv) LogWarn

func (e *BaseEnv) LogWarn(msg string) bool

LogWarn 输出 warn 日志(附带 logid),返回 true 便于嵌入条件表达式

func (*BaseEnv) ReqBody

func (e *BaseEnv) ReqBody() string

ReqBody 返回请求体内容(有 IO 成本,谨慎在热路径使用)

func (*BaseEnv) ReqBodyJson

func (e *BaseEnv) ReqBodyJson(path string) string

ReqBodyJson 用 gjson 路径取请求体 JSON 字段,不存在返回 ""(结果按请求缓存)

func (*BaseEnv) ReqCip

func (e *BaseEnv) ReqCip() string

ReqCip 返回客户端 IP(真实源 IP,可能为空串)

func (*BaseEnv) ReqCookie

func (e *BaseEnv) ReqCookie(key string) string

ReqCookie 返回指定 cookie 的值,不存在返回 ""

func (*BaseEnv) ReqErr

func (e *BaseEnv) ReqErr() string

ReqErr 返回 BFE 处理错误码字符串,无错误返回 ""

func (*BaseEnv) ReqHeader

func (e *BaseEnv) ReqHeader(key string) string

ReqHeader 返回指定请求头的值,不存在返回 ""

func (*BaseEnv) ReqHost

func (e *BaseEnv) ReqHost() string

ReqHost 返回 Host(去掉端口,保留原始大小写)

func (*BaseEnv) ReqLogid

func (e *BaseEnv) ReqLogid() string

func (*BaseEnv) ReqMethod

func (e *BaseEnv) ReqMethod() string

func (*BaseEnv) ReqPath

func (e *BaseEnv) ReqPath() string

func (*BaseEnv) ReqPort

func (e *BaseEnv) ReqPort() string

ReqPort 返回 Host 中的端口,缺省 "80"(与旧 PortFetcher 语义一致)

func (*BaseEnv) ReqProto

func (e *BaseEnv) ReqProto() string

ReqProto 返回协议(http/https/h2 等,等价旧 ProtoFetcher)

func (*BaseEnv) ReqQuery

func (e *BaseEnv) ReqQuery(key string) string

ReqQuery 返回指定 query 参数的第一个值,不存在返回 ""

func (*BaseEnv) ReqQueryAll

func (e *BaseEnv) ReqQueryAll(key string) []string

ReqQueryAll 返回指定 query 参数的全部值

func (*BaseEnv) ReqQueryKeys

func (e *BaseEnv) ReqQueryKeys() []string

ReqQueryKeys 返回全部 query key

func (*BaseEnv) ReqRetry

func (e *BaseEnv) ReqRetry() int

func (*BaseEnv) ReqSip

func (e *BaseEnv) ReqSip() string

ReqSip 返回对端 socket IP

func (*BaseEnv) ReqTags

func (e *BaseEnv) ReqTags(name string) []string

ReqTags 返回指定类型的全部 tag

func (*BaseEnv) ReqUri

func (e *BaseEnv) ReqUri() string

ReqUri 返回原始 RequestURI(path + query)

func (*BaseEnv) ReqVip

func (e *BaseEnv) ReqVip() string

ReqVip 返回访问的 VIP

func (*BaseEnv) ReqVport

func (e *BaseEnv) ReqVport() string

ReqVport 返回会话的虚拟端口

func (*BaseEnv) ResCode

func (e *BaseEnv) ResCode() int

func (*BaseEnv) ResHeader

func (e *BaseEnv) ResHeader(key string) string

func (*BaseEnv) RouteCluster

func (e *BaseEnv) RouteCluster() string

func (*BaseEnv) RouteHostTag

func (e *BaseEnv) RouteHostTag() string

func (*BaseEnv) RouteProduct

func (e *BaseEnv) RouteProduct() string

func (*BaseEnv) RouteSubCluster

func (e *BaseEnv) RouteSubCluster() string

func (*BaseEnv) SesSecure

func (e *BaseEnv) SesSecure() bool

func (*BaseEnv) SesSni

func (e *BaseEnv) SesSni() string

SesSni 返回 TLS SNI,无则 ""

func (*BaseEnv) SesTlsClientCa

func (e *BaseEnv) SesTlsClientCa() string

SesTlsClientCa 返回签发客户端证书的 CA 名,无则 ""

func (*BaseEnv) SesTrusted

func (e *BaseEnv) SesTrusted() bool

SesTrusted 对端是否为可信来源(等价旧 req_cip_trusted)

type Condition

type Condition struct {
	// contains filtered or unexported fields
}

Condition 新风格条件表达式,实现 condition.Condition 接口(Match)

func Compile

func Compile(src string) (*Condition, error)

Compile 编译新风格条件表达式;结果必须是 bool 类型

func CompileLegacy

func CompileLegacy(src string) (*Condition, error)

CompileLegacy 编译兼容旧原语的条件串: legacyPatcher 把旧原语名重写为 Env 方法后统一走新引擎,旧/新/混写均可。 先经 ValidateLegacyArgs 做旧原语字面量参数校验(对齐旧实现加载期拒绝非法配置的行为)。 编译失败时由调用方决定是否回退旧引擎。

func MustCompile

func MustCompile(src string) *Condition

MustCompile 同 Compile,编译失败时 panic(仅用于测试和确定的常量表达式)

func (*Condition) Match

func (c *Condition) Match(req *bfe_basic.Request) bool

Match 求值:运行期错误按 false 处理并输出 warn 日志,不影响请求处理

func (*Condition) String

func (c *Condition) String() string

type ConfEnv

type ConfEnv struct{}

ConfEnv 提供配置表数据的表达式访问(本期 stub)

func (*ConfEnv) MapTable

func (e *ConfEnv) MapTable(name, key string) string

MapTable 按名字取映射表中 key 的值(本期 stub,返回 "")

func (*ConfEnv) StrTable

func (e *ConfEnv) StrTable(name string) []string

StrTable 按名字取 []string 表(本期 stub,返回 nil)

type Env

type Env struct {
	BaseEnv   // ReqXxx / ResXxx / 路由集群 / SesXxx / Env / LogXxx
	TimeEnv   // Now / InTimeRange / InPeriodicRange
	HashEnv   // Hash / IpIn / IpRange / Rand / RandInt / Srand
	VarEnv    // ReqContext / UsrVarXxx / UsrVarSetXxx(请求级)
	RedisEnv  // GetRedisClient* / RedisClient.Get|GetInt|HGetAll,见 redis_env.go
	HttpEnv   // http 访问(本期 stub),见 http_env.go
	GlbEnv    // 进程级变量(本期 stub),见 glb_env.go
	ConfEnv   // 配置表访问(本期 stub),见 conf_env.go
	InnerEnv  // 旧 %var 内置变量函数(BfeClientIp 等),见 inner_env.go
	LegacyEnv // 旧原语方法(ReqMethodIn 等),配合 legacyPatcher 兼容旧条件串
}

Env 是表达式求值上下文,按域拆分为多个子 env(匿名嵌入,方法提升)

func GetEnv

func GetEnv(req *bfe_basic.Request) *Env

GetEnv 返回请求级 Env(懒创建并按请求缓存,同一请求的所有表达式求值共享)。 注意:目标仓库 Request.Context 为无锁 map,与既有 SetContext/GetContext 用法 保持一致;同一请求的处理若为并发场景,调用方需自行保证时序安全。

func NewEnv

func NewEnv(req *bfe_basic.Request) *Env

NewEnv 创建一个绑定到指定请求的 Env(每请求一次)

type GlbEnv

type GlbEnv struct{}

GlbEnv 进程级用户变量(本期 stub)

func (*GlbEnv) GlbVar

func (e *GlbEnv) GlbVar(name string) string

GlbVar 读取 string 型变量(本期 stub,返回 "")

func (*GlbEnv) GlbVarBool

func (e *GlbEnv) GlbVarBool(name string) bool

GlbVarBool 读取 bool 型变量(本期 stub,返回 false)

func (*GlbEnv) GlbVarDecr

func (e *GlbEnv) GlbVarDecr(name string) int

GlbVarDecr 计数减一并返回新值(本期 stub,返回 0)

func (*GlbEnv) GlbVarFloat

func (e *GlbEnv) GlbVarFloat(name string) float64

GlbVarFloat 读取 float64 型变量(本期 stub,返回 0)

func (*GlbEnv) GlbVarIncr

func (e *GlbEnv) GlbVarIncr(name string) int

GlbVarIncr 计数加一并返回新值(本期 stub,返回 0)

func (*GlbEnv) GlbVarIncrBy

func (e *GlbEnv) GlbVarIncrBy(name string, delta int) int

GlbVarIncrBy 计数加 delta 并返回新值(本期 stub,返回 0)

func (*GlbEnv) GlbVarInt

func (e *GlbEnv) GlbVarInt(name string) int

GlbVarInt 读取 int 型变量(本期 stub,返回 0)

func (*GlbEnv) GlbVarSetBool

func (e *GlbEnv) GlbVarSetBool(name string, value bool) bool

GlbVarSetBool 写入 bool 型变量(本期 stub,返回写入值)

func (*GlbEnv) GlbVarSetFloat

func (e *GlbEnv) GlbVarSetFloat(name string, value float64) float64

GlbVarSetFloat 写入 float64 型变量(本期 stub,返回写入值)

func (*GlbEnv) GlbVarSetInt

func (e *GlbEnv) GlbVarSetInt(name string, value int) int

GlbVarSetInt 写入 int 型变量(本期 stub,返回写入值)

func (*GlbEnv) GlbVarSetStr

func (e *GlbEnv) GlbVarSetStr(name, value string) string

GlbVarSetStr 写入 string 型变量(本期 stub,返回写入值)

func (*GlbEnv) GlbVarStr

func (e *GlbEnv) GlbVarStr(name string) string

GlbVarStr 读取 string 型变量(本期 stub,返回 "")

type HashEnv

type HashEnv struct {
	// contains filtered or unexported fields
}

func (*HashEnv) Hash

func (e *HashEnv) Hash(value string) int

Hash 返回 value 的哈希桶号 [0, HashBucketSize): murmur3(小写归一(value)) % HashBucketSize;value 为 "" 时返回本请求内稳定的随机桶。

func (*HashEnv) IpIn

func (e *HashEnv) IpIn(ip string, cidrs []string) bool

IpIn 判断 ip 是否命中 cidrs 列表,元素支持单 IP 和 CIDR(如 ["10.0.0.0/8"])。 ip 或列表元素解析失败按未命中处理。

func (*HashEnv) IpRange

func (e *HashEnv) IpRange(ip, start, end string) bool

IpRange 判断 ip 是否在 [start, end] 区间内(v4/v6 不混用;解析失败返回 false)。

func (*HashEnv) Rand

func (e *HashEnv) Rand() float64

Rand 返回 [0, 1) 的随机数,每次调用产生新值; 需要跨规则复用时先存入用户变量(UsrVarSetXxx)。

func (*HashEnv) RandInt

func (e *HashEnv) RandInt(max int) int

RandInt 返回 [0, max) 的随机整数,每次调用产生新值。

func (*HashEnv) Srand

func (e *HashEnv) Srand(seed int) int

Srand 用 seed 重播种本请求的随机源,不影响其他请求;典型用途是配合调试头复现灰度结果。 返回 seed 本身(expr 不支持无返回值函数,返回值无语义,可忽略)。

type HttpClient

type HttpClient struct{}

HttpClient http client 表达式句柄(本期 stub,所有方法返回零值)

func (*HttpClient) Do

func (c *HttpClient) Do(method, rawURL, contentType, body string, headerKv ...string) *HttpResp

Do 发起请求(本期 stub)

func (*HttpClient) Get

func (c *HttpClient) Get(rawURL string, headerKv ...string) *HttpResp

Get 发起 GET 请求(本期 stub)

func (*HttpClient) Post

func (c *HttpClient) Post(rawURL, contentType, body string, headerKv ...string) *HttpResp

Post 发起 POST 请求(本期 stub)

func (*HttpClient) WithHeader

func (c *HttpClient) WithHeader(name, value string) *HttpClient

WithHeader 返回带默认请求头的 client 副本(本期 stub)

type HttpEnv

type HttpEnv struct{}

HttpEnv 提供表达式内的 http 访问函数(本期 stub)

func (*HttpEnv) GetHttpClient

func (e *HttpEnv) GetHttpClient(timeoutMs int) *HttpClient

GetHttpClient 按超时返回 client(本期 stub)

func (*HttpEnv) HttpGet

func (e *HttpEnv) HttpGet(url string, headerKv ...string) *HttpResp

HttpGet 发起 GET 请求(本期 stub)

func (*HttpEnv) HttpPost

func (e *HttpEnv) HttpPost(url, contentType, body string, headerKv ...string) *HttpResp

HttpPost 发起 POST 请求(本期 stub)

func (*HttpEnv) HttpService

func (e *HttpEnv) HttpService(name string) *HttpClient

HttpService 按名字获取 http 服务(本期 stub)

type HttpResp

type HttpResp struct{}

HttpResp http 响应句柄(本期 stub,所有方法返回零值)

func (*HttpResp) Body

func (r *HttpResp) Body() string

Body 返回响应体(本期 stub,返回 "")

func (*HttpResp) BodyJson

func (r *HttpResp) BodyJson(path string) string

BodyJson 按路径取响应体 JSON 字段(本期 stub,返回 "")

func (*HttpResp) Header

func (r *HttpResp) Header(name string) string

Header 按名字取响应头(本期 stub,返回 "")

func (*HttpResp) Status

func (r *HttpResp) Status() int

Status 返回 HTTP 状态码(本期 stub,返回 0)

type InnerEnv

type InnerEnv struct {
	// contains filtered or unexported fields
}

InnerEnv 旧 %var 内置变量函数(委托 action.VariableHandlers,语义逐项等价)

func (*InnerEnv) BfeBackendInfo

func (e *InnerEnv) BfeBackendInfo() string

func (*InnerEnv) BfeBip

func (e *InnerEnv) BfeBip() string

func (*InnerEnv) BfeCip

func (e *InnerEnv) BfeCip() string

for connection info

func (*InnerEnv) BfeClientIp

func (e *InnerEnv) BfeClientIp() string

for client

func (*InnerEnv) BfeClientIpLocation

func (e *InnerEnv) BfeClientIpLocation() string

func (*InnerEnv) BfeClientPort

func (e *InnerEnv) BfeClientPort() string

func (*InnerEnv) BfeDomainAuto

func (e *InnerEnv) BfeDomainAuto() string

func (*InnerEnv) BfeLogid

func (e *InnerEnv) BfeLogid() string

func (*InnerEnv) BfeProtocol

func (e *InnerEnv) BfeProtocol() string

func (*InnerEnv) BfeRip

func (e *InnerEnv) BfeRip() string

func (*InnerEnv) BfeRouteCluster

func (e *InnerEnv) BfeRouteCluster() string

for backend BfeRouteCluster 对应旧变量 %bfe_cluster(路由目标集群 req.Route.ClusterName)。 注意与 BaseEnv.RouteCluster(后端集群 req.Backend.ClusterName)区分。

func (*InnerEnv) BfeServerName

func (e *InnerEnv) BfeServerName() string

for bfe

func (*InnerEnv) BfeSslCipher

func (e *InnerEnv) BfeSslCipher() string

func (*InnerEnv) BfeSslInfo

func (e *InnerEnv) BfeSslInfo() string

for tls

func (*InnerEnv) BfeSslJa3Hash

func (e *InnerEnv) BfeSslJa3Hash() string

func (*InnerEnv) BfeSslJa3Raw

func (e *InnerEnv) BfeSslJa3Raw() string

func (*InnerEnv) BfeSslResume

func (e *InnerEnv) BfeSslResume() string

func (*InnerEnv) BfeSslVersion

func (e *InnerEnv) BfeSslVersion() string

func (*InnerEnv) BfeVip

func (e *InnerEnv) BfeVip() string

func (*InnerEnv) ClientCertAduCarRole

func (e *InnerEnv) ClientCertAduCarRole() string

func (*InnerEnv) ClientCertAduReserve

func (e *InnerEnv) ClientCertAduReserve() string

func (*InnerEnv) ClientCertIssuerString

func (e *InnerEnv) ClientCertIssuerString() string

func (*InnerEnv) ClientCertPem

func (e *InnerEnv) ClientCertPem() string

func (*InnerEnv) ClientCertPubKeyAlgo

func (e *InnerEnv) ClientCertPubKeyAlgo() string

func (*InnerEnv) ClientCertSerialNumber

func (e *InnerEnv) ClientCertSerialNumber() string

for client certificate

func (*InnerEnv) ClientCertSigAlgo

func (e *InnerEnv) ClientCertSigAlgo() string

func (*InnerEnv) ClientCertSubjectCommonName

func (e *InnerEnv) ClientCertSubjectCommonName() string

func (*InnerEnv) ClientCertSubjectCountry

func (e *InnerEnv) ClientCertSubjectCountry() string

func (*InnerEnv) ClientCertSubjectLocality

func (e *InnerEnv) ClientCertSubjectLocality() string

func (*InnerEnv) ClientCertSubjectOrganization

func (e *InnerEnv) ClientCertSubjectOrganization() string

func (*InnerEnv) ClientCertSubjectOrganizationUnit

func (e *InnerEnv) ClientCertSubjectOrganizationUnit() string

func (*InnerEnv) ClientCertSubjectProvince

func (e *InnerEnv) ClientCertSubjectProvince() string

func (*InnerEnv) ClientCertSubjectString

func (e *InnerEnv) ClientCertSubjectString() string

func (*InnerEnv) ClientCertSubjectTitle

func (e *InnerEnv) ClientCertSubjectTitle() string

func (*InnerEnv) SessionId

func (e *InnerEnv) SessionId() string

type LegacyEnv

type LegacyEnv struct {
	// contains filtered or unexported fields
}

LegacyEnv 旧原语方法集,方法内通过 env 调用新取数方法实现

func (*LegacyEnv) BfePeriodicTimeRange

func (l *LegacyEnv) BfePeriodicTimeRange(start, end, period string) bool

BfePeriodicTimeRange 旧 bfe_periodic_time_range:period 非空在旧实现为加载期报错,运行期按 false

func (*LegacyEnv) BfeTimeRange

func (l *LegacyEnv) BfeTimeRange(start, end string) bool

func (*LegacyEnv) DefaultT

func (l *LegacyEnv) DefaultT() bool

func (*LegacyEnv) ReqBodyContain

func (l *LegacyEnv) ReqBodyContain(patterns string, fold bool) bool

ReqBodyContain 旧 req_body_contain(预留实现,legacyNameMap 暂不映射)

func (*LegacyEnv) ReqBodyJsonIn

func (l *LegacyEnv) ReqBodyJsonIn(path, patterns string, fold bool) bool

func (*LegacyEnv) ReqCipHashIn

func (l *LegacyEnv) ReqCipHashIn(sections string) bool

func (*LegacyEnv) ReqCipRange

func (l *LegacyEnv) ReqCipRange(start, end string) bool

func (*LegacyEnv) ReqCipTrusted

func (l *LegacyEnv) ReqCipTrusted() bool

func (*LegacyEnv) ReqContextValueIn

func (l *LegacyEnv) ReqContextValueIn(key, patterns string, fold bool) bool

ReqContextValueIn 旧 req_context_value_in:Context 值须为 string,否则 false

func (*LegacyEnv) ReqCookieKeyIn

func (l *LegacyEnv) ReqCookieKeyIn(keys string) bool

func (*LegacyEnv) ReqCookieValueContain

func (l *LegacyEnv) ReqCookieValueContain(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqCookieValueHashIn

func (l *LegacyEnv) ReqCookieValueHashIn(key, sections string, insensitive bool) bool

func (*LegacyEnv) ReqCookieValueIn

func (l *LegacyEnv) ReqCookieValueIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqCookieValuePrefixIn

func (l *LegacyEnv) ReqCookieValuePrefixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqCookieValueSuffixIn

func (l *LegacyEnv) ReqCookieValueSuffixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqHeaderKeyIn

func (l *LegacyEnv) ReqHeaderKeyIn(keys string) bool

func (*LegacyEnv) ReqHeaderValueContain

func (l *LegacyEnv) ReqHeaderValueContain(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqHeaderValueHashIn

func (l *LegacyEnv) ReqHeaderValueHashIn(key, sections string, insensitive bool) bool

func (*LegacyEnv) ReqHeaderValueIn

func (l *LegacyEnv) ReqHeaderValueIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqHeaderValuePrefixIn

func (l *LegacyEnv) ReqHeaderValuePrefixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqHeaderValueRegmatch

func (l *LegacyEnv) ReqHeaderValueRegmatch(key, pattern string) bool

func (*LegacyEnv) ReqHeaderValueSuffixIn

func (l *LegacyEnv) ReqHeaderValueSuffixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqHostIn

func (l *LegacyEnv) ReqHostIn(patterns string) bool

ReqHostIn 旧 req_host_in:plain split + ToUpper 精确匹配

func (*LegacyEnv) ReqHostRegmatch

func (l *LegacyEnv) ReqHostRegmatch(pattern string) bool

func (*LegacyEnv) ReqHostSuffixIn

func (l *LegacyEnv) ReqHostSuffixIn(patterns string) bool

func (*LegacyEnv) ReqHostTagIn

func (l *LegacyEnv) ReqHostTagIn(patterns string) bool

func (*LegacyEnv) ReqMethodIn

func (l *LegacyEnv) ReqMethodIn(patterns string) bool

func (*LegacyEnv) ReqPathContain

func (l *LegacyEnv) ReqPathContain(patterns string, fold bool) bool

func (*LegacyEnv) ReqPathElementPrefixIn

func (l *LegacyEnv) ReqPathElementPrefixIn(patterns string, fold bool) bool

ReqPathElementPrefixIn 旧 req_path_element_prefix_in: 模式与路径都补尾 "/"(不重复补),fold 转大写后做前缀匹配

func (*LegacyEnv) ReqPathIn

func (l *LegacyEnv) ReqPathIn(patterns string, fold bool) bool

func (*LegacyEnv) ReqPathPrefixIn

func (l *LegacyEnv) ReqPathPrefixIn(patterns string, fold bool) bool

func (*LegacyEnv) ReqPathRegmatch

func (l *LegacyEnv) ReqPathRegmatch(pattern string) bool

func (*LegacyEnv) ReqPathSuffixIn

func (l *LegacyEnv) ReqPathSuffixIn(patterns string, fold bool) bool

func (*LegacyEnv) ReqPortIn

func (l *LegacyEnv) ReqPortIn(patterns string) bool

func (*LegacyEnv) ReqProtoMatch

func (l *LegacyEnv) ReqProtoMatch(pattern string) bool

func (*LegacyEnv) ReqProtoSecure

func (l *LegacyEnv) ReqProtoSecure() bool

func (*LegacyEnv) ReqQueryExist

func (l *LegacyEnv) ReqQueryExist() bool

func (*LegacyEnv) ReqQueryKeyIn

func (l *LegacyEnv) ReqQueryKeyIn(keys string) bool

func (*LegacyEnv) ReqQueryKeyPrefixIn

func (l *LegacyEnv) ReqQueryKeyPrefixIn(keys string) bool

func (*LegacyEnv) ReqQueryValueContain

func (l *LegacyEnv) ReqQueryValueContain(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqQueryValueHashIn

func (l *LegacyEnv) ReqQueryValueHashIn(key, sections string, insensitive bool) bool

func (*LegacyEnv) ReqQueryValueIn

func (l *LegacyEnv) ReqQueryValueIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqQueryValuePrefixIn

func (l *LegacyEnv) ReqQueryValuePrefixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqQueryValueRegmatch

func (l *LegacyEnv) ReqQueryValueRegmatch(key, pattern string) bool

func (*LegacyEnv) ReqQueryValueSuffixIn

func (l *LegacyEnv) ReqQueryValueSuffixIn(key, patterns string, fold bool) bool

func (*LegacyEnv) ReqTagMatch

func (l *LegacyEnv) ReqTagMatch(key, value string) bool

ReqTagMatch 旧 req_tag_match:tag 按 ":" 取首段比较

func (*LegacyEnv) ReqUaRegmatch

func (l *LegacyEnv) ReqUaRegmatch(pattern string) bool

func (*LegacyEnv) ReqUrlRegmatch

func (l *LegacyEnv) ReqUrlRegmatch(pattern string) bool

func (*LegacyEnv) ReqVipIn

func (l *LegacyEnv) ReqVipIn(patterns string) bool

ReqVipIn 旧 req_vip_in:单 IP 精确匹配,不支持 CIDR

func (*LegacyEnv) ReqVipRange

func (l *LegacyEnv) ReqVipRange(start, end string) bool

func (*LegacyEnv) ResCodeIn

func (l *LegacyEnv) ResCodeIn(patterns string) bool

ResCodeIn 旧 res_code_in:状态码转字符串后精确匹配(字符串比较语义)

func (*LegacyEnv) ResHeaderKeyIn

func (l *LegacyEnv) ResHeaderKeyIn(keys string) bool

func (*LegacyEnv) ResHeaderValueIn

func (l *LegacyEnv) ResHeaderValueIn(key, patterns string, fold bool) bool

func (*LegacyEnv) SesSipRange

func (l *LegacyEnv) SesSipRange(start, end string) bool

func (*LegacyEnv) SesTlsClientCaIn

func (l *LegacyEnv) SesTlsClientCaIn(patterns string) bool

SesTlsClientCaIn 旧 ses_tls_client_ca_in

func (*LegacyEnv) SesTlsSniIn

func (l *LegacyEnv) SesTlsSniIn(patterns string) bool

func (*LegacyEnv) SesVipRange

func (l *LegacyEnv) SesVipRange(start, end string) bool

type Param

type Param struct {
	// contains filtered or unexported fields
}

Param 代表一个动作参数:expr 表达式(加载期预编译)或字面量

func CompileParam

func CompileParam(src string) (*Param, error)

CompileParam 加载期编译单个动作参数。 "=" 前缀按 expr 表达式编译(返回值必须 string);"==" 开头转义为字面量; 其余为普通字符串。编译失败返回错误(由调用方使配置加载失败,不回退)。

func CompileParams

func CompileParams(params []string) ([]*Param, error)

CompileParams 加载期批量编译(对应 []string params)

func (*Param) Eval

func (p *Param) Eval(req *bfe_basic.Request) (string, error)

Eval 运行期求值。字面量直接返回;表达式经 GetEnv(req) 求值。 错误向上传播,由调用方按约定处理(EvalParams 为置空继续)。

func (*Param) IsExpr

func (p *Param) IsExpr() bool

IsExpr 该参数是否为表达式

func (*Param) String

func (p *Param) String() string

String 返回原始配置串

type RedisClient

type RedisClient struct {
	// contains filtered or unexported fields
}

RedisClient redis client 表达式句柄(单例,进程级共享,勿按请求缓存)

func (*RedisClient) Get

func (c *RedisClient) Get(key string) string

Get 读取 string 值;miss/错误/类型不符返回 ""

func (*RedisClient) GetInt

func (c *RedisClient) GetInt(key string) int

GetInt 读取整数值(string 存储解析);miss/错误/解析失败返回 0

func (*RedisClient) HGetAll

func (c *RedisClient) HGetAll(key string) map[string]string

HGetAll 读取 Hash;miss/错误返回空 map

type RedisEnv

type RedisEnv struct{}

RedisEnv 提供表达式内的 redis 访问函数

func (*RedisEnv) GetRedisClient

func (e *RedisEnv) GetRedisClient(addr string) *RedisClient

GetRedisClient 按地址返回单例 redis client,使用默认超时/连接池参数。 addr 支持 bns 名或 ip:port(格式见 redis_client.Options.ServiceConf)。

func (*RedisEnv) GetRedisClientWithOpts

func (e *RedisEnv) GetRedisClientWithOpts(addr, password string,
	connTimeoutMs, readTimeoutMs, writeTimeoutMs int) *RedisClient

GetRedisClientWithOpts 按地址与参数返回单例 redis client。 同一 地址+参数 组合只创建一次连接池,重复调用(含不同表达式/请求)返回同一实例; 相同 key 再次传入不同参数时,以首次创建的实例为准。

type TimeEnv

type TimeEnv struct {
	// contains filtered or unexported fields
}

func (*TimeEnv) InPeriodicRange

func (e *TimeEnv) InPeriodicRange(start, end string) bool

InPeriodicRange 判断当前时刻是否落在每天周期时段内(闭区间)。 时间格式与旧 bfe_periodic_time_range 相同(hhmmssZ,Z 为时区)。

func (*TimeEnv) InTimeRange

func (e *TimeEnv) InTimeRange(start, end string) bool

InTimeRange 判断 Now() 是否在 [start, end] 内(闭区间)。 时间格式与旧 bfe_time_range 相同(如 "2024-01-01 00:00:00 +0800");格式非法返回 false。

func (*TimeEnv) Now

func (e *TimeEnv) Now() time.Time

Now 返回当前时间(UTC);请求带 X-Bfe-Debug-Time 头时取该调试时间。 注意与 expr 内置 now() 区分:内置函数不受调试头影响,请统一使用 Now()。

type VarEnv

type VarEnv struct {
	// contains filtered or unexported fields
}

func (*VarEnv) ReqContext

func (e *VarEnv) ReqContext(key interface{}) interface{}

ReqContext 按 key 读取请求 Context 值,不存在返回 nil

func (*VarEnv) UsrVar

func (e *VarEnv) UsrVar(name string) string

UsrVar 是 UsrVarStr 的简写

func (*VarEnv) UsrVarBool

func (e *VarEnv) UsrVarBool(name string) bool

UsrVarBool 读取 bool 型用户变量:原生 bool 直取;string 存储按 "true"/"false" 解析; 缺失/类型不符/解析失败返回 false

func (*VarEnv) UsrVarFloat

func (e *VarEnv) UsrVarFloat(name string) float64

UsrVarFloat 读取 float64 型用户变量:原生 float64 直取;string 存储则 ParseFloat 解析; 缺失/类型不符/解析失败返回 0

func (*VarEnv) UsrVarInt

func (e *VarEnv) UsrVarInt(name string) int

UsrVarInt 读取 int 型用户变量:原生 int 直取;string 存储则 Atoi 解析; 缺失/类型不符/解析失败返回 0

func (*VarEnv) UsrVarSet

func (e *VarEnv) UsrVarSet(name, value string) string

UsrVarSet 是 UsrVarSetStr 的简写

func (*VarEnv) UsrVarSetBool

func (e *VarEnv) UsrVarSetBool(name string, value bool) bool

UsrVarSetBool 写入 bool 型用户变量,返回写入值

func (*VarEnv) UsrVarSetFloat

func (e *VarEnv) UsrVarSetFloat(name string, value float64) float64

UsrVarSetFloat 写入 float64 型用户变量,返回写入值

func (*VarEnv) UsrVarSetInt

func (e *VarEnv) UsrVarSetInt(name string, value int) int

UsrVarSetInt 写入 int 型用户变量(原生类型入 Context),返回写入值

func (*VarEnv) UsrVarSetStr

func (e *VarEnv) UsrVarSetStr(name, value string) string

UsrVarSetStr 写入 string 型用户变量(与 legacy USR_VAR_SET 同一存储),返回写入值

func (*VarEnv) UsrVarStr

func (e *VarEnv) UsrVarStr(name string) string

UsrVarStr 读取 string 型用户变量,不存在或非 string 存储返回 ""

Jump to

Keyboard shortcuts

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