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.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
ctx | context.Context | Yes | The context of the request. |
roleKey | string | Yes | The 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:
ErrorCode | Cause |
|---|---|
NotFound | HTTP 404: no role 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. |