crud

package
v0.15.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2025 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 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 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 ReadWithRetry

func ReadWithRetry(
	ctx context.Context,
	readFunc func(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse),
	readReq resource.ReadRequest,
	stateContainer StateContainer,
	opts ReadWithRetryOptions,
) error

ReadWithRetry executes a read operation with retry logic within the context timeout It repeatedly calls the provided read function until success or context timeout

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 CreateResponseContainer

type CreateResponseContainer struct {
	*resource.CreateResponse
}

CreateResponseContainer wraps resource.CreateResponse to implement StateContainer

func (*CreateResponseContainer) GetState

func (c *CreateResponseContainer) GetState() tfsdk.State

func (*CreateResponseContainer) SetState

func (c *CreateResponseContainer) SetState(state tfsdk.State)

type Identifiable

type Identifiable interface {
	GetID() types.String
}

Identifiable is an interface for types that have an ID

type ReadWithRetryOptions

type ReadWithRetryOptions struct {
	// MaxRetries is the maximum number of retry attempts (default: 30)
	MaxRetries int
	// RetryInterval is the time to wait between retries (default: 2 seconds)
	RetryInterval time.Duration
	// Operation is the name of the operation for logging (e.g., "Create", "Update")
	Operation string
	// ResourceTypeName is the optional resource type name for logging
	ResourceTypeName string
}

ReadWithRetryOptions configures the retry behavior for reading resource state

func DefaultReadWithRetryOptions

func DefaultReadWithRetryOptions() ReadWithRetryOptions

DefaultReadWithRetryOptions returns sensible default options for most use cases

type StateContainer

type StateContainer interface {
	GetState() tfsdk.State
	SetState(tfsdk.State)
}

StateContainer interface for anything that has a State field

type UpdateResponseContainer

type UpdateResponseContainer struct {
	*resource.UpdateResponse
}

UpdateResponseContainer wraps resource.UpdateResponse to implement StateContainer

func (*UpdateResponseContainer) GetState

func (c *UpdateResponseContainer) GetState() tfsdk.State

func (*UpdateResponseContainer) SetState

func (c *UpdateResponseContainer) SetState(state tfsdk.State)

Directories

Path Synopsis
graph_beta

Jump to

Keyboard shortcuts

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