feat: add idempotent batch task submission and recovery examples

This commit is contained in:
2026-09-17 21:21:18 +08:00
parent a8a8dcfe1e
commit 571107f96d
27 changed files with 1375 additions and 24 deletions

View File

@@ -93,19 +93,31 @@ func validID(id string) bool {
return true
}
func (c *Client) call(ctx context.Context, method, path, key string, in, out any) error {
if method != "GET" {
if err := validateIdempotencyKey(key); err != nil {
return err
}
}
return c.callJSON(ctx, method, path, key, in, out)
}
func validateIdempotencyKey(key string) error {
if len(key) < 1 || len(key) > 128 {
return errors.New("a stable Idempotency-Key of 1 to 128 ASCII characters is required")
}
for _, ch := range key {
if ch < 33 || ch > 126 {
return errors.New("Idempotency-Key must not contain spaces or control characters")
}
}
return nil
}
// callJSON 仅执行有界HTTP交换;写入调用者负责校验整项或批量内的独立幂等键。
func (c *Client) callJSON(ctx context.Context, method, path, key string, in, out any) error {
if c.token == "" {
return errors.New("Orbit token is required for business APIs")
}
if method != "GET" {
if len(key) < 1 || len(key) > 128 {
return errors.New("a stable Idempotency-Key of 1 to 128 ASCII characters is required")
}
for _, ch := range key {
if ch < 33 || ch > 126 {
return errors.New("Idempotency-Key must not contain spaces or control characters")
}
}
}
var body []byte
var err error
if in != nil {