crud

package
v0.1.1-alpha Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2024 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

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

func IsNotFoundError(err error) bool

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

type Identifiable interface {
	GetID() types.String
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL