Skip to main content

Delete a role with the Go SDK

Permit.Api.Roles.Delete() deletes a role and all its related data, including the permissions granted to the role, from the environment that your API key belongs to. This reference is for Go developers who manage role-based access control (RBAC) roles from backend code.

warning

Roles.Delete removes the role and all its related data in one call. The Go SDK has no method to restore a deleted role.

Roles.Delete signature

func (r *Roles) Delete(ctx context.Context, roleKey string) error

Roles.Delete parameters

ParameterTypeRequiredDescription
ctxcontext.ContextYesThe context of the request.
roleKeystringYesThe key of the role to delete. The role ID also works.

Example: delete a role with Roles.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 role-key with the key of your role:

err := Permit.Api.Roles.Delete(ctx, "role-key")

Roles.Delete return value and errors

Roles.Delete returns only an error, which is nil when the role 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 role 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.