Documentation
¶
Index ¶
- func AssignmentExistsInSlice[T Assignment](assignment T, assignments []T, compareFunc CompareFunc) bool
- func DefaultAssignmentsEqual(a, b Assignment) bool
- func ExistsInSlice[T any](item T, slice []T, compareFunc CompareFunc) bool
- func HandleReadErrorIfNotFound(ctx context.Context, resp *resource.ReadResponse, resource ResourceWithID, ...)
- func HandleTimeout(ctx context.Context, ...) (context.Context, context.CancelFunc)
- func HandleUpdateErrorIfNotFound(ctx context.Context, resp *resource.UpdateResponse, resource ResourceWithID, ...)
- func IdentifiableExistsInSlice[T Identifiable](item T, slice []T) bool
- func IsNotFoundError(err error) bool
- type Assignment
- type CompareFunc
- type Identifiable
- type ResourceWithID
- type StateWithID
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignmentExistsInSlice ¶
func AssignmentExistsInSlice[T Assignment](assignment T, assignments []T, compareFunc CompareFunc) bool
AssignmentExistsInSlice checks if a given assignment exists in a slice of assignments
func DefaultAssignmentsEqual ¶
func DefaultAssignmentsEqual(a, b Assignment) bool
DefaultAssignmentsEqual compares two Assignment instances for equality
func ExistsInSlice ¶
func ExistsInSlice[T any](item T, slice []T, compareFunc CompareFunc) bool
ExistsInSlice checks if a given item exists in a slice based on a comparison function
func HandleReadErrorIfNotFound ¶
func HandleReadErrorIfNotFound(ctx context.Context, resp *resource.ReadResponse, resource ResourceWithID, state StateWithID, err error)
HandleReadErrorIfNotFound handles errors during the read operation.
func HandleTimeout ¶
func HandleTimeout(ctx context.Context, timeoutFunc func(context.Context, time.Duration) (time.Duration, diag.Diagnostics), defaultTimeout time.Duration, diags *diag.Diagnostics) (context.Context, context.CancelFunc)
HandleTimeout is a helper function to manage context timeouts
func HandleUpdateErrorIfNotFound ¶
func HandleUpdateErrorIfNotFound(ctx context.Context, resp *resource.UpdateResponse, resource ResourceWithID, state StateWithID, err error)
HandleUpdateErrorIfNotFound handles errors during the update operation.
func IdentifiableExistsInSlice ¶
func IdentifiableExistsInSlice[T Identifiable](item T, slice []T) bool
IdentifiableExistsInSlice checks if a given identifiable item exists in a slice based on ID
func IsNotFoundError ¶
IsNotFoundError checks if the given error is an OData error indicating that a resource was not found. The function first verifies if the error is not nil. Then, it attempts to cast the error to an ODataError type from the Microsoft Graph SDK. If the casting is successful, the function retrieves the main error details using the GetErrorEscaped method of the ODataError struct. It then checks if the error code or message contains indications of a "not found" error.
Specifically, the function looks for the error codes "request_resourcenotfound" and "resourcenotfound" (case-insensitive), or a message containing the phrase "not found" (case-insensitive). If any of these conditions are met, the function returns true, indicating that the error is a "not found" error. Otherwise, it returns false.
The ODataError struct is part of the Microsoft Graph SDK and includes various methods and properties to handle API errors. The main error details are encapsulated in a nested structure that provides additional context, such as error codes and descriptive messages.
Usage:
if common.IsNotFoundError(err) { // Handle the "not found" error case }
Parameters:
err - The error to check.
Returns:
bool - True if the error indicates that a resource was not found, otherwise false.
Types ¶
type Assignment ¶
type Assignment interface { Identifiable GetTarget() interface{} }
Assignment is a generic interface for types that represent assignments
type CompareFunc ¶
type CompareFunc func(a, b interface{}) bool
CompareFunc is a type for custom comparison functions
type Identifiable ¶
Identifiable is an interface for types that have an ID
type ResourceWithID ¶
type ResourceWithID interface {
GetTypeName() string
}
ResourceWithID is an interface that represents a resource with an ID.
type StateWithID ¶
type StateWithID interface {
GetID() string
}
StateWithID is an interface that represents a state model with an ID.