Skip to main content

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.

warning

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

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
resourceKeystringYesThe 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:

ErrorCodeCause
NotFoundHTTP 404: no resource with that key or ID exists in the environment.
Unauthorized, ForbiddenAccessHTTP 401 or 403: the API key is invalid or has no access to the environment.
UnexpectedErrorA server error (HTTP 5xx) or a network error.