util

package
v0.1.0-alpha.5 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Any

func Any[T comparable](ts []T, value T) bool

Any returns true if any element of the array is equal to the value.

func CheckLastN

func CheckLastN[T comparable](ts []T, n int, values ...T) bool

CheckLastN returns true if the last n elements of the array are equal to any of the values. If the array does not have the desired count of elements, it returns false.

func DataSourceTypeName

func DataSourceTypeName(req datasource.MetadataRequest, name string) string

DataSourceTypeName constructs the type name for the data source of the provider.

func Deref

func Deref[T any](a *T) T

Deref returns the value under the pointer.

If the pointer is nil, it returns an empty value.

func FirewallRanges

func FirewallRanges(frs *[]string) []types.String

func FirstNotEmpty

func FirstNotEmpty(ss ...string) string

FirstNotEmpty returns the first encountered not empty string if present.

func FirstSetStringValue

func FirstSetStringValue(ss ...types.String) types.String

FirstSetStringValue returns the first set string value. If not found, it returns an unset string.

func HandleError

func HandleError(resp *http.Response, ierr error, numTries int) (*http.Response, error)

HandleError overrides the default behavior of the library by exposing the underlying issue because the underlying issue may be useful, e.g., a customer running out of credits and still closing the body.

This function is called if retries are expired, containing the last status from the http library. If not specified, default behavior for the library is to close the body and return an error indicating how many tries were attempted.

The function is called only when server returns 500s.

func Join

func Join[A any](ss []A, separator string) string

func Map

func Map[A, B any](as []A, f func(A) B) []B

Map applies the function f to each element of the input list and returns a new list containing the results. The input list is not modified. The function f should take an element of the input list as its argument and return a value of a different type. The output list has the same length as the input list.

func MaybeBody

func MaybeBody(resp StatusCoder) string

func MaybeBool

func MaybeBool(b types.Bool) *bool

func MaybeBoolValue

func MaybeBoolValue(b *bool) types.Bool

func MaybeString

func MaybeString(s types.String) *string

func MaybeStringValue

func MaybeStringValue(s *string) types.String

func NewHTTPClient

func NewHTTPClient() *http.Client

NewHTTPClient creates an HTTP client for the Terraform provider.

func NewTimeValidator

func NewTimeValidator() validator.String

NewTimeValidator returns an AttributeValidator which ensures that any configured attribute value:

  • Is a string.
  • Matches the string format RFC3339.
  • Is UTC.

Null (unconfigured) and unknown (known after apply) values are skipped.

func NewUUIDValidator

func NewUUIDValidator() validator.String

NewUUIDValidator returns an AttributeValidator which ensures that any configured attribute value:

  • Is a string.
  • Matches the UUID format.

Null (unconfigured) and unknown (known after apply) values are skipped.

func Ptr

func Ptr[A any](a A) *A

Ptr returns a pointer to the input value.

func ReadNotEmptyFileTrimmed

func ReadNotEmptyFileTrimmed(path string) (string, error)

ReadNotEmptyFileTrimmed reads the file at path and returns the white space trimmed non-empty content.

func ResourceTypeName

func ResourceTypeName(req resource.MetadataRequest, name string) string

ResourceTypeName constructs the type name for the resource of the provider.

func StringFirewallRanges

func StringFirewallRanges(frs []types.String) []string

func TerraformProviderUserAgent

func TerraformProviderUserAgent(version string) string

TerraformProviderUserAgent identifies the provider as a versioned User Agent.

func ToString

func ToString(s types.String) string

func UUIDStringValue

func UUIDStringValue(id otypes.UUID) types.String

func WorkspaceGroupStateStringValue

func WorkspaceGroupStateStringValue(wgs management.WorkspaceGroupState) types.String

func WorkspaceStateString

func WorkspaceStateString(wgs types.String) *management.WorkspaceState

func WorkspaceStateStringValue

func WorkspaceStateStringValue(ws management.WorkspaceState) types.String

Types

type StatusCoder

type StatusCoder interface {
	StatusCode() int
}

type StatusOKOption

type StatusOKOption func(code int) (overrideReturn bool, newResult *SummaryWithDetailError)

type SummaryWithDetailError

type SummaryWithDetailError struct {
	Summary string
	Detail  string
}

func MapWithError

func MapWithError[A, B any](as []A, f func(A) (B, *SummaryWithDetailError)) ([]B, *SummaryWithDetailError)

MapWithError applies the function f to each element of the input list and returns a new list containing the results. The input list is not modified. The function f should take an element of the input list as its argument and return a value of a different type. The output list has the same length as the input list. If the converter returns an error, the first error is returned and no result.

func ReturnNilOnNotFound

func ReturnNilOnNotFound(code int) (bool, *SummaryWithDetailError)

func StatusOK

func StatusOK(resp StatusCoder, ierr error,
	opts ...StatusOKOption,
) *SummaryWithDetailError

func (SummaryWithDetailError) Error

func (swd SummaryWithDetailError) Error() string

Jump to

Keyboard shortcuts

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