Documentation
¶
Index ¶
- Constants
- Variables
- func AddConfig(name string, conf map[string]any)
- func ConvertActionJSONToYAML(source string) (string, error)
- func Encrypt(plaintext string) (string, error)
- func ExportGoStructs(packageName string) string
- func GetActionConfig(actionName string) (map[string]any, []*safe.SafeBuf)
- func GetBytesOrSafe(v any) ([]byte, func())
- func GetManifest() map[string]any
- func GetStringOrSafe(v any) (string, func())
- func Load(name string) error
- func MergeMap(dst, src map[string]any)
- func ModelConfigured(name, model string) bool
- func ParseActionYAML(source string) (map[string]any, error)
- func PatchActionTokens(source string, tokens []string) (string, error)
- func RegisterAction(name string, definition any)
- func RegisterFilter(name string, filter Filter)
- func RegisterJSFilter(name, code string)
- func RegisterJSSigner(name, code string)
- func RegisterSigner(name string, s Signer)
- func RemoveAction(name string)
- func RemoveFilter(name string)
- func RemoveSigner(name string)
- func ReplaceConfig(name string, conf map[string]any)
- func SetConfig(name string, conf map[string]any)
- func SetEncryptKeys(key, iv []byte)
- func SetJSRunner(runner func(context.Context, string, map[string]any) (map[string]any, error))
- type Action
- type CallLog
- type CallOptions
- type ConfigurableAction
- type Filter
- type FormatAction
- type GenericAction
- func (a *GenericAction) ActionName() string
- func (a *GenericAction) Config() map[string]any
- func (a *GenericAction) GetFormat() string
- func (a *GenericAction) GetMethod() string
- func (a *GenericAction) GetURL() string
- func (a *GenericAction) MarshalJSON() ([]byte, error)
- func (a *GenericAction) SignerName() string
- type HttpRequest
- type MethodAction
- type MockInputError
- type ProtectedValueResolver
- type Result
- type Signer
- type SignerAction
- type StreamOptions
- type URLAction
- type ValidatableAction
Constants ¶
const ProtectedValuesContextKey = "ProtectedValues"
ProtectedValuesContextKey identifies the request-scoped protected-value resolver.
Variables ¶
var GlobalConfigs = map[string]any{}
GlobalConfigs 存储整棵配置树
Functions ¶
func ConvertActionJSONToYAML ¶
ConvertActionJSONToYAML converts a legacy JSON Action document to readable block-style YAML. It does not add defaults or modify the Action semantics.
func ExportGoStructs ¶
ExportGoStructs 根据全局配置生成 Go 结构体代码
func GetActionConfig ¶
GetActionConfig 获取某个动作经过层级合并后的完整配置,返回配置图和需要手动关闭的 SafeBuf 列表
func GetBytesOrSafe ¶
GetBytesOrSafe 从配置中安全地获取字节切片。如果是 SafeBuf,则返回明文副本及对应的清理函数
func GetStringOrSafe ¶
GetStringOrSafe 从配置中安全地获取字符串值。如果是 SafeBuf,则返回明文副本及对应的清理函数
func ModelConfigured ¶
ModelConfigured checks a dynamic model Action without making a request or exposing its configuration. Use the same inheritance resolver as CallBy.
func ParseActionYAML ¶
ParseActionYAML parses a data-driven Action definition without applying product-specific defaults or registering it globally.
func PatchActionTokens ¶
PatchActionTokens replaces the top-level tokens field while preserving the rest of the YAML document, including comments and field order.
func RegisterAction ¶
RegisterAction 注册 API 动作。 definition 可以是一个结构体实例(用作类型模板)或一个 map[string]any(用作动态定义)。
func RegisterFilter ¶
RegisterFilter registers a reusable request/response filter.
func RegisterJSFilter ¶
func RegisterJSFilter(name, code string)
RegisterJSFilter registers an administrator-managed JavaScript filter.
func RegisterJSSigner ¶
func RegisterJSSigner(name, code string)
RegisterJSSigner registers an administrator-managed JavaScript signer.
func RemoveSigner ¶
func RemoveSigner(name string)
RemoveSigner unregisters a custom signer. Built-in signers are retained.
func ReplaceConfig ¶
ReplaceConfig replaces one configuration root. It is intended for dynamic stores such as DocDB where removed fields must disappear immediately.
Types ¶
type Action ¶
type Action interface {
ActionName() string // 例如: "tencent.sms.send"
}
Action 是所有接口的基础标识接口
type CallLog ¶
type CallLog struct {
log.BaseLog
Action string `log:"pos:6,color:cyan"`
Method string `log:"pos:7,color:gray"`
URL string `log:"pos:8,color:gray"`
StatusCode int `log:"pos:9,color:magenta,keyname:Status"`
Code string `log:"pos:10,color:magenta"`
Error string `log:"pos:11,color:red"`
UsedTime float32 `log:"pos:12,color:green,precision:6"`
Stream bool `log:"pos:13"`
ResponseSize int64 `log:"pos:14,color:magenta,keyname:Size"`
RequestData any `log:"pos:15,color:cyan,keyname:Request"`
ResponseData any `log:"pos:16,color:magenta,keyname:Response"`
}
type CallOptions ¶
type CallOptions struct {
Context context.Context
Token string
Config map[string]any
Timeout time.Duration
Logger *log.Logger
Stream *StreamOptions
Timing bool
// Mode defaults to live. Mock uses only the Action's declared fixture.
Mode string
// InputPreview logs at most 20 Unicode characters from the first text input.
InputPreview bool
}
CallOptions controls one API invocation without changing the stored Action.
type ConfigurableAction ¶
ConfigurableAction 定义可以提供默认硬编码配置的动作
type Filter ¶
type Filter interface {
Apply(ctx context.Context, event string, input map[string]any) (map[string]any, error)
}
Filter transforms one request or response event. Implementations must be stateless; per-call state is passed through input["state"] and returned as output["state"].
type FormatAction ¶
type FormatAction interface {
GetFormat() string // 返回: "json", "form", "multipart"
}
FormatAction 定义请求体格式
type GenericAction ¶
type GenericAction struct {
// contains filtered or unexported fields
}
GenericAction 是一个动态 Action 容器,实现了所有 API 相关接口
func (*GenericAction) ActionName ¶
func (a *GenericAction) ActionName() string
func (*GenericAction) Config ¶
func (a *GenericAction) Config() map[string]any
func (*GenericAction) GetFormat ¶
func (a *GenericAction) GetFormat() string
func (*GenericAction) GetMethod ¶
func (a *GenericAction) GetMethod() string
func (*GenericAction) GetURL ¶
func (a *GenericAction) GetURL() string
func (*GenericAction) MarshalJSON ¶
func (a *GenericAction) MarshalJSON() ([]byte, error)
func (*GenericAction) SignerName ¶
func (a *GenericAction) SignerName() string
type HttpRequest ¶
type HttpRequest struct {
Context context.Context
Url string
Method string
Payload any
// contains filtered or unexported fields
}
HttpRequest 内部使用的请求描述结构,供 Signer 使用
func (*HttpRequest) GetHeader ¶
func (r *HttpRequest) GetHeader(key string) string
GetHeader 获取指定 Header 的值
func (*HttpRequest) SetHeader ¶
func (r *HttpRequest) SetHeader(key string, values ...any)
SetHeader 提供无感知的安全 Header 设置功能。支持传入多个参数进行自动拼接。 如果参数中包含 *safe.SafeBuf, *safe.SecretPlaintext 或 []byte (标记为敏感), 整个生成的 Header 缓冲区都将被注册用于后置物理擦除。 安全的拼接与转换(如 safe.Concat, safe.Base64)建议使用 safe 包提供的返回 *safe.SafeBuf 的方法。
type MethodAction ¶
type MethodAction interface {
GetMethod() string // 例如: "GET"
}
MethodAction 定义显式指定方法的动作
type MockInputError ¶
type MockInputError struct{}
MockInputError identifies a rejected test input, rather than a broken fixture or failed execution. Callers can record this expected negative outcome.
func (*MockInputError) Error ¶
func (*MockInputError) Error() string
type ProtectedValueResolver ¶
type ProtectedValueResolver interface {
OpenProtected(reference string) (*safe.SecretPlaintext, error)
}
ProtectedValueResolver opens references owned by the current low-code call.
type Result ¶
type Result struct {
Mode string
Simulated bool
Ok bool
StatusCode int
Headers map[string]string
Data any
Code string
Error string
ErrorDetail any
Timing map[string]any
// contains filtered or unexported fields
}
Result 定义 API 调用的标准返回结果
type Signer ¶
type Signer interface {
Sign(req *HttpRequest, config map[string]any) error
}
Signer 负责为请求附加签名信息
type SignerAction ¶
type SignerAction interface {
SignerName() string // 例如: "tc3"
}
SignerAction 定义需要签名的动作
type StreamOptions ¶
type StreamOptions struct {
OnHeaders func(result map[string]any) error
OnData func(data []byte) error
OnDone func(result map[string]any) error
}
StreamOptions receives the upstream response synchronously on the calling goroutine.
type ValidatableAction ¶
type ValidatableAction interface {
Validate() error
}
ValidatableAction 定义支持自我校验的动作