utils

package
v0.55.4 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2022 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "utils",
	Short: "Various utility methods",
}

Command represents the utils command.

View Source
var (
	SignalCtx = getSignalContext()
)

Functions

func Base64Encode added in v0.20.0

func Base64Encode(data string) string

Base64Encode base 64 encodes a string.

func CreateMockEmptyGetResponse added in v0.32.0

func CreateMockEmptyGetResponse() func(ctx context.Context, url string) ([]byte, error)

func CreateMockGetResponse added in v0.32.0

func CreateMockGetResponse(response string, err error) func(ctx context.Context, url string) ([]byte, error)

func GetDefaultConfigDirectory added in v0.8.11

func GetDefaultConfigDirectory() (string, error)

GetDefaultConfigDirectory returns the full path to the .newrelic directory within the user's home directory.

func GetTimestamp added in v0.8.11

func GetTimestamp() int64

GetTimestamp returns the current epoch timestamp in seconds.

func IntSliceToStringSlice added in v0.30.0

func IntSliceToStringSlice(in []int) (out []string)

func IsAbsoluteURL added in v0.32.0

func IsAbsoluteURL(rawURL string) bool

func IsExitStatusCode added in v0.36.10

func IsExitStatusCode(exitCode int, err error) bool

func LogIfError added in v0.4.0

func LogIfError(err error)

LogIfError wraps the err nil check to cleanup the code. Logs at Error level

func LogIfFatal added in v0.4.0

func LogIfFatal(err error)

LogIfFatal wraps the err nil check to cleanup the code. Logs at Fatal level

func MakeRange added in v0.18.27

func MakeRange(min, max int) []int

MakeRange generates a slice of sequential integers.

func MinOf added in v0.8.11

func MinOf(vars ...int) int

MinOf returns the minimum int value provided.

func Obfuscate added in v0.30.0

func Obfuscate(input string) string

Obfuscate receives a string, and replaces everything after the first 8 characters with an asterisk before returning the result.

func StdinExists added in v0.24.0

func StdinExists() bool

Standard way to check for stdin in most environments (https://stackoverflow.com/questions/22563616/determine-if-stdin-has-data-with-go)

func StringInSlice added in v0.28.0

func StringInSlice(str string, slice []string) bool

func StructToMap

func StructToMap(item interface{}, fields []string) map[string]interface{}

Types

type HTTPClient added in v0.32.0

type HTTPClient struct {
	// contains filtered or unexported fields
}

func (*HTTPClient) Do added in v0.32.0

func (c *HTTPClient) Do(req *http.Request) (*http.Response, error)

func (*HTTPClient) Get added in v0.32.0

func (c *HTTPClient) Get(ctx context.Context, url string) ([]byte, error)

func (*HTTPClient) Post added in v0.36.0

func (c *HTTPClient) Post(ctx context.Context, url string, requestBody []byte) ([]byte, error)

type HTTPClientInterface added in v0.32.0

type HTTPClientInterface interface {
	Get(ctx context.Context, url string) ([]byte, error)
	Post(ctx context.Context, url string, requestBody []byte) ([]byte, error)
	Do(req *http.Request) (*http.Response, error)
}

func NewHTTPClient added in v0.32.0

func NewHTTPClient(apiKey string) HTTPClientInterface

type MockHTTPClient added in v0.32.0

type MockHTTPClient struct {
	GetCallCount int
	MockDoFunc   MockHTTPDoFunc
}

func NewMockHTTPClient added in v0.32.0

func NewMockHTTPClient(mockDoFunc MockHTTPDoFunc) *MockHTTPClient

func (*MockHTTPClient) Do added in v0.32.0

func (c *MockHTTPClient) Do(req *http.Request) (*http.Response, error)

func (*MockHTTPClient) Get added in v0.32.0

func (c *MockHTTPClient) Get(ctx context.Context, url string) ([]byte, error)

type MockHTTPDoFunc added in v0.32.0

type MockHTTPDoFunc func(req *http.Request) (*http.Response, error)

func CreateMockHTTPDoFunc added in v0.32.0

func CreateMockHTTPDoFunc(mockResponse string, statusCode int, err error) MockHTTPDoFunc

CreateMockHTTPDoFunc is a helper function to create mock responses for the MockHTTPClient. In short, it simulates the http.Client.Do() method.

type NRDBClient added in v0.26.0

type NRDBClient interface {
	QueryWithContext(context.Context, int, nrdb.NRQL) (*nrdb.NRDBResultContainer, error)
}

type Retry added in v0.27.1

type Retry struct {
	MaxRetries int

	RetryFunc func() error
	// contains filtered or unexported fields
}

func NewRetry added in v0.27.1

func NewRetry(maxRetries int, retryDelayMs int, retryFunc func() error) *Retry

func (*Retry) ExecWithRetries added in v0.27.1

func (r *Retry) ExecWithRetries(ctx context.Context) *RetryContext

type RetryContext added in v0.33.0

type RetryContext struct {
	RetryCount int
	Errors     []error
	Success    bool
	Canceled   bool
}

func (*RetryContext) MostRecentError added in v0.33.0

func (c *RetryContext) MostRecentError() error

type StructToMapCallback

type StructToMapCallback func(item interface{}, fields []string) map[string]interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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