Documentation
¶
Index ¶
- Constants
- func BuildHTTPClient(opts HTTPOptions) *http.Client
- func CheckAllowedURL(rawURL string, allowed []string, denyLoopback bool) error
- func DecryptIfNeeded(ciphertext string) (string, error)
- func DecryptPayload(payload map[string]any) (map[string]any, error)
- func EncryptIfNeeded(plaintext string) (string, error)
- func EncryptPayload(payload map[string]any, reservedKeys ...string) (map[string]any, error)
- func HTTPRequest(ctx context.Context, client *http.Client, rawURL, method string, ...) (map[string]any, error)
- func HasEncryptedPayload(payload map[string]any) bool
- func InitGlobalEncryptor(key string, enabled bool) error
- func IsEncrypted(data string) bool
- func Logf(logger Logger, ctx context.Context, level string, format string, args ...any)
- type HTTPOptions
- type Logger
- type ModuleDef
Constants ¶
View Source
const EnvHTTPAllowedDomains = "SCRIPT_HTTP_ALLOWED_DOMAINS"
Variables ¶
This section is empty.
Functions ¶
func BuildHTTPClient ¶
func BuildHTTPClient(opts HTTPOptions) *http.Client
func CheckAllowedURL ¶
func DecryptIfNeeded ¶
DecryptIfNeeded 解密带 enc: 前缀的字符串,普通明文直接透传。
func DecryptPayload ¶
DecryptPayload 解密带加密标记的载荷;未加密载荷原样返回。
func EncryptIfNeeded ¶
EncryptIfNeeded 在加密器启用时加密 plaintext,否则原样返回。
func EncryptPayload ¶
EncryptPayload 加密载荷,并保留 reservedKeys 指定的路由字段。
func HTTPRequest ¶
func HasEncryptedPayload ¶
HasEncryptedPayload 判断载荷是否标记为已加密。
func InitGlobalEncryptor ¶
InitGlobalEncryptor 初始化全局 AES-GCM 加密器。enabled 为 false 时保留明文透传行为。
Types ¶
type HTTPOptions ¶
type HTTPOptions struct {
AllowedDomains []string
Timeout time.Duration
MaxResponseBody int64
DenyLoopback bool
}
func HTTPAllowlistFromEnv ¶
func HTTPAllowlistFromEnv() HTTPOptions
func NormalizeHTTPOptions ¶
func NormalizeHTTPOptions(o HTTPOptions) HTTPOptions
type Logger ¶
type Logger interface {
Debug(ctx context.Context, msg string, args ...any)
Info(ctx context.Context, msg string, args ...any)
Warn(ctx context.Context, msg string, args ...any)
Error(ctx context.Context, msg string, args ...any)
}
Logger 定义宿主模块所需的最小日志接口。
type ModuleDef ¶
ModuleDef 是语言无关的宿主模块定义。Name 是模块名,Funcs 保存脚本可调用的 Go 函数。
func ModuleCrypto ¶
func ModuleCrypto() ModuleDef
ModuleCrypto 构建提供字符串、JSON 和 SHA-256 操作的 crypto 模块。
func ModuleHTTP ¶
func ModuleHTTP(opts HTTPOptions) ModuleDef
func ModuleLogger ¶
ModuleLogger 构建提供 info、warn、error、debug 及其格式化版本的 log 模块。
func ModuleUtil ¶
ModuleUtil 构建提供 sleep、time、timestamp 和 date 操作的 util 模块。 maxSleep 限制脚本 sleep 的最长时间,默认值为 5 秒。
Click to show internal directories.
Click to hide internal directories.