util

package
v0.0.0-...-9fc8b42 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: UPL-1.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright (c) 2025, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

Copyright (c) 2024, Oracle and/or its affiliates. Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BoolPtr

func BoolPtr(v bool) *bool

func CreateUploadCertificateKey

func CreateUploadCertificateKey() (string, error)

func ExponentialRetry

func ExponentialRetry(ftor retryFunc, arg interface{}) (interface{}, bool, error)

ExponentialRetry executes a functor at some interval until is either succeeds, fails in a non-recoverable way, or a timeout is reached. The given functor is called with the given arguments each interval.

func ExponentialRetryImpl

func ExponentialRetryImpl(ftor retryFunc, arg interface{}, start time.Duration, max time.Duration, factor time.Duration, timeout time.Duration) (interface{}, bool, error)

ExponentialRetryImpl executes a functor at some interval until is either succeeds, fails in a non-recoverable way, or a timeout is reached. The given functor is called with the given arguments each interval. 'start' is the first duration to wait. 'max' is the maximum duration. 'factor' is the amount to increase the wait each iteration. 'timeout' is the last time to start a request. Due to the fact that a functor call may be long, this function may take longer than the given timeout.

func ExponentialRetryTimeout

func ExponentialRetryTimeout(ftor retryFunc, arg interface{}, timeout time.Duration) (interface{}, bool, error)

ExponentialRetryTimeout executes a functor at some interval until is either succeeds, fails in a non-recoverable way, or a timeout is reached. The given functor is called with the given arguments each interval.

func FileIsTTY

func FileIsTTY(f *os.File) (bool, error)

FileIsTTY gives a best guess that a given file represents a TTY or PTY. The current best guess is that the file is a character device.

While it is possible for character devices not to be TTYs, it is unlikely to be true in the context of this code. A common counterexample is something like a disk. If someone is trying to do something like pipe a disk to stdin, then they are being silly and some odd behavior can be tolerated.

func FilesFromPath

func FilesFromPath(path string) ([]string, error)

func InMemoryFile

func InMemoryFile(name string) (string, error)

InMemoryFile returns the filename of a file that exists only in memory. It can be used with all typical file operations except for deletion.

func IncrementCount

func IncrementCount(in string, delim string) string

IncrementCount adds one to a string that has a number at the end or appends a 1 to a string that does not. Empty strings are returned unmodified.

func Int32Ptr

func Int32Ptr(v int32) *int32

func Int64Ptr

func Int64Ptr(v int64) *int64

func IntPtr

func IntPtr(v int) *int

func IsNil

func IsNil(v interface{}) bool

IsNil is a mostly complete way of checking if a value is nil. It still misses some esoteric types of values.

See: https://go.dev/doc/faq#nil_error

func LinearRetry

func LinearRetry(ftor retryFunc, arg interface{}) (interface{}, bool, error)

LinearRetry executes a functor every 'wait' until it either succeeds, fails in a way that should not be retries, or until the timeout of 10 seconds is reached. If the functor succeeds, the function returns false with no error. If the functor fails in a way that should not be retried, the function returns true with an error. If the function times out, it returns false as well as the last error from the functor.

func LinearRetryImpl

func LinearRetryImpl(ftor retryFunc, arg interface{}, wait time.Duration, timeout time.Duration) (interface{}, bool, error)

LinearRetryImpl executes a functor every 'wait' until it either succeeds, fails in a way that should not be retries, or until the timeout is reached. If the functor succeeds, the function returns false with no error. If the functor fails in a way that should not be retried, the function returns true with an error. If the function times out, it returns false as well as the last error from the functor.

func LinearRetryTimeout

func LinearRetryTimeout(ftor retryFunc, arg interface{}, timeout time.Duration) (interface{}, bool, error)

LinearRetryTimeout executes a functor every 'wait' until it either succeeds, fails in a way that should not be retries, or until the timeout is reached. If the functor succeeds, the function returns false with no error. If the functor fails in a way that should not be retried, the function returns true with an error. If the function times out, it returns false as well as the last error from the functor.

func ResolveURIToIP

func ResolveURIToIP(uri *url.URL) (string, bool, error)

ResolveURIToIP extracts a reasonable candidate for an IP address from the given URI. If the URI can reasonably be said to point to the host, the second return value is "true", otherwise it is "false".

func StrPtr

func StrPtr(v string) *string

func TemplateToString

func TemplateToString(templateString string, contents interface{}) (string, error)

func TemplateToStringWithFuncs

func TemplateToStringWithFuncs(templateString string, contents interface{}, funcs map[string]any) (string, error)

Types

type JsonPatch

type JsonPatch struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value string `json:"value"`
}

type JsonPatches

type JsonPatches struct {
	Patches []*JsonPatch
}

func (*JsonPatches) AddPatch

func (jp *JsonPatches) AddPatch(op string, path []string, value string) *JsonPatches

func (*JsonPatches) Replace

func (jp *JsonPatches) Replace(path []string, value string) *JsonPatches

func (*JsonPatches) String

func (jp *JsonPatches) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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