helpers

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package helpers contains helper functions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommaDelimitedOptionalValue

func CommaDelimitedOptionalValue(vals []string) *string

CommaDelimitedOptionalValue takes an array of strings and returns a pointer to a string containing all values concatenated with commas, or nil if the array is empty.

func Subtract added in v0.0.7

func Subtract(left map[string]bool, right map[string]bool) []string
Subtract takes two maps and returns a slice of keys that exist in the left map but not the right.

left is the map to subtract from.

right is the map to subtract.

The function returns a slice of keys that exist in left but not right.

Types

type HTTPResponse

type HTTPResponse interface {
	StatusCode() int
	Status() string
}

type TaskPoller

type TaskPoller[T HTTPResponse] struct {
	// contains filtered or unexported fields
}

TaskPoller is a helper to poll an API for the status of an asynchronous task. It will call the provided taskFunc to get the latest task status and will continue polling until the task completes (succeeds or fails) or an error occurs.

func NewTaskPoller

func NewTaskPoller[T HTTPResponse](taskFunc func() (T, error)) *TaskPoller[T]

NewTaskPoller creates a new TaskPoller. taskFunc is a function that will be called to get the latest status of the task. It should return a HTTPResponse and an error.

func (*TaskPoller[T]) Err

func (s *TaskPoller[T]) Err() error

Err returns the first error encountered while polling.

func (*TaskPoller[T]) Poll

func (s *TaskPoller[T]) Poll(ctx context.Context) bool

Poll calls taskFunc to get the latest task status. It will continue polling until the task completes (succeeds or fails) or an error occurs. Returns true if polling should continue, false otherwise.

func (*TaskPoller[T]) Resp

func (s *TaskPoller[T]) Resp() T

Resp returns the latest response from calling taskFunc.

Jump to

Keyboard shortcuts

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