Delete a resource with the Go SDK
Permit.Api.Resources.Delete() deletes a resource and all its related data from the environment that your API key belongs to. This reference is for Go developers who maintain their policy schema from backend code.
Resources.Delete removes the resource and all its related data in one call. The Go SDK has no method to restore a deleted resource.
Resources.Delete signature
func (r *Resources) Delete(ctx context.Context, resourceKey string) error
Resources.Delete parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The context of the request. |
resourceKey | string | Yes | The key of the resource to delete. The resource ID also works. |
Example: delete a resource with Resources.Delete
The example uses a client named Permit, created with permit.NewPermit() as shown in Check permissions with the Go SDK, and a ctx of type context.Context. Replace resourceKey with the key of your resource:
err := Permit.Api.Resources.Delete(ctx, "resourceKey")
Resources.Delete return value and errors
Resources.Delete returns only an error, which is nil when the resource is deleted.
If the call fails, err holds an errors.PermitError from the github.com/permitio/permit-golang/pkg/errors package. Its StatusCode field has the HTTP status, and its ErrorCode field has one of these codes:
ErrorCode | Cause |
|---|---|
NotFound | HTTP 404: no resource with that key or ID exists in the environment. |
Unauthorized, ForbiddenAccess | HTTP 401 or 403: the API key is invalid or has no access to the environment. |
UnexpectedError | A server error (HTTP 5xx) or a network error. |