Go SDK
Enforce ReQlo decisions from Go 1.21+, with context cancellation, approvals, delegations and webhook verification.
The Go SDK is server-side, uses only the standard library, and supports Go 1.21+. A *reqlo.Client is safe for
concurrent use: create one and share it.
go get github.com/ReQlo-intelligence/reqlo-goEnforce before acting
Enforce returns a nil error only on allow. Deny and approval required return a *reqlo.DeniedError; timeouts,
network failures and HTTP errors return other errors. Run the action only after a nil error.
import (
"context"
"errors"
"fmt"
"os"
reqlo "github.com/ReQlo-intelligence/reqlo-go"
)
var client, _ = reqlo.New(os.Getenv("REQLO_API_KEY"))
func ReadDocument(ctx context.Context, session Session, documentID string) (string, error) {
doc, err := documents.Get(ctx, documentID) // authoritative facts from your database
if err != nil {
return "", err
}
_, err = client.Enforce(ctx, reqlo.AuthorizeRequest{
Agent: reqlo.Agent{ID: "<YOUR_AGENT_ID>"},
Subject: &reqlo.Subject{ID: session.UserID, Kind: "user"}, // from your verified session
Action: "documents.read",
Resource: reqlo.Resource{Type: "document", ID: doc.ID, Attributes: map[string]any{"owner_id": doc.OwnerID}},
Context: map[string]any{"document_classification": doc.Classification},
})
var denied *reqlo.DeniedError
if errors.As(err, &denied) {
return "", fmt.Errorf("not allowed: %s", denied.Decision.ReasonCode)
}
if err != nil {
return "", err // no decision: the document is not read
}
return doc.Content, nil
}Authorize returns the *reqlo.Decision without treating deny as an error. Act only when
decision.Decision == reqlo.DecisionAllow. Cancelling ctx stops the request.
Approvals and delegations
held, _ := client.Authorize(ctx, request)
if held.Decision == reqlo.DecisionApprovalRequired {
saveForLater(request, held.Approval.ID) // redeem later with request.ApprovalID once approved
}
approval, err := client.Approvals.Retrieve(ctx, approvalID)
pending, err := client.Approvals.List(ctx, "pending")
grant, err := client.Delegations.Create(ctx, reqlo.DelegationCreateParams{
AgentID: "<YOUR_AGENT_ID>", Subject: reqlo.Subject{ID: "usr_94", Kind: "user"},
Actions: []string{"calendar.schedule"}, ExpiresAt: "2026-12-31T00:00:00Z",
})
list, err := client.Delegations.List(ctx, reqlo.DelegationListParams{SubjectID: "usr_94"})
_, err = client.Delegations.Revoke(ctx, grant.ID)Webhooks
func receive(w http.ResponseWriter, r *http.Request) {
body, _ := io.ReadAll(io.LimitReader(r.Body, 1<<20))
event, err := reqlo.ConstructEvent(body, r.Header.Get("Reqlo-Signature"), os.Getenv("REQLO_WEBHOOK_SECRET"), time.Now())
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return
}
if event.Type == "approval.requested" {
notifyApprovers(event.Data.Object.ID)
}
w.WriteHeader(http.StatusNoContent)
}Configuration
client, err := reqlo.New(apiKey,
reqlo.WithTimeout(3*time.Second), // per attempt
reqlo.WithMaxRetries(2), // 429 and 5xx only, with backoff
reqlo.WithHTTPClient(myClient), // proxies or instrumentation; redirects are never followed
)Timeouts and network errors are never retried, and Delegations.Create is never retried, because a request that
timed out may have reached ReQlo.
Errors
| Error | When |
|---|---|
*reqlo.DeniedError | Enforce got deny or approval required. .Decision has the reason. |
*reqlo.APIError | HTTP error. .Status, .Code and .RequestID. |
reqlo.ErrTimeout, reqlo.ErrNetwork | No answer. Check with errors.Is. |
reqlo.ErrResponse | A malformed response. Never permission to act. |
*reqlo.ConfigurationError | Invalid options or arguments. |
reqlo.ErrInvalidSignature | A webhook signature is missing, invalid or too old. |
Something wrong or unclear? Report an issue with this page.