util

package
v1.8.9 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

Log is the shared Lumber Logger logging to console and after calling SetupLogging also to file

Functions

func CheckError

func CheckError(err error, msg string) bool

func CheckProperty

func CheckProperty(properties map[string]string, property string) (string, error)

func ConvertMicrosecondsToUnixTime added in v1.1.0

func ConvertMicrosecondsToUnixTime(timeInMicroseconds int64) time.Time

ConvertMicrosecondsToUnixTime converts the UTC time in microseconds to a time.Time struct (unix time)

func CreateTestFileSystem added in v1.5.1

func CreateTestFileSystem() afero.Fs

CreateTestFileSystem creates a virtual filesystem with 2 layers. The first layer allows to read file from the disk the second layer allows to modify files on a virtual filesystem

func FailOnError

func FailOnError(err error, msg string)

func GenerateUuidFromConfigId added in v1.8.0

func GenerateUuidFromConfigId(projectUniqueId string, configId string) (string, error)

GenerateUuidFromConfigId takes the unique project identifier within an environment, a config id and generates a valid UUID based on provided information

func GenerateUuidFromName added in v1.7.0

func GenerateUuidFromName(name string) (string, error)

GenerateUuidFromName generates a fixed UUID from a given configuration name. This is used when dealing with select Dynatrace APIs that do not/or no longer support unique name properties. As a convention between monaco and such APIs, both monaco and Dynatrace will generate the same name-based UUID using UUID v3 (MD5 hash based) with a "dynatrace.com" URL namespace UUID.

func IsRequestLoggingActive added in v1.3.0

func IsRequestLoggingActive() bool

func IsResponseLoggingActive added in v1.5.0

func IsResponseLoggingActive() bool

func IsUuid added in v1.8.0

func IsUuid(configId string) bool

IsUuid tests whether a potential configId is already a UUID

func LogRequest added in v1.3.0

func LogRequest(id string, request *http.Request) error

func LogResponse added in v1.5.0

func LogResponse(id string, response *http.Response, body string) error

func PrintError added in v1.5.0

func PrintError(err error)

PrintError should pretty-print the error using a more user-friendly format

func PrintErrors added in v1.5.0

func PrintErrors(errors []error)

func ReplacePathSeparators

func ReplacePathSeparators(path string) (newPath string)

func SanitizeName added in v1.5.1

func SanitizeName(name string) string

SanitizeName removes special characters, limits to max 254 characters in name, no special characters

func SetupLogging

func SetupLogging(verbose bool) error

SetupLogging is used to initialize the shared file Logger once the necessary setup config is available

func StringTimestampToHumanReadableFormat added in v1.1.0

func StringTimestampToHumanReadableFormat(unixTimestampAsString string) (humanReadable string, parsedTimestamp int64, err error)

StringTimestampToHumanReadableFormat parses and sanity-checks a unix timestamp as string and returns it as int64 and a human-readable representation of it

func UnmarshalYaml

func UnmarshalYaml(text string, fileName string) (error, map[string]map[string]string)

UnmarshalYaml takes the contents of a yaml file and converts it to a map[string]map[string]string The yaml file should have the following format:

some-name-1:

  • list-key-1: "list-entry-1"
  • list-key-2: "list-entry-2"

some-name-2:

  • list-key-1: "list-entry-1"

func ValidateAndParseJson added in v1.3.0

func ValidateAndParseJson(jsonString string, filename string) (map[string]interface{}, error)

ValidateJson validates whether the json file is correct, by using the internal validation done when unmarshalling to a an object. As none of our jsons can actually be unmarshalled to a string, we catch that error, but report any other error as fatal. We then return the parsed json object.

func ValidateJson added in v1.1.0

func ValidateJson(json string, filename string) error

Types

type JsonValidationError added in v1.1.0

type JsonValidationError struct {

	// FileName is the file name (full qualified) where the error happened
	// This field is always filled.
	FileName string
	// LineNumber contains the line number (starting by one) where the error happened
	// If we don't have the information, this is -1.
	LineNumber int
	// CharacterNumberInLine contains the character number (starting by one) where
	// the error happened. If we don't have the information, this is -1.
	CharacterNumberInLine int
	// LineContent contains the full line content of where the error happened
	// If we don't have the information, this is an empty string.
	LineContent string
	// PreviousLineContent contains the full line content of the line before LineContent
	// If we don't have the information, this is an empty string.
	PreviousLineContent string
	// Cause is the original error which happened during the json unmarshalling.
	Cause error
}

JsonValidationError is an error which contains more information about where the error appeared in the json file which was validated. It contains the fileName, line number, character number, and line content as additional information. Furthermore, it contains the original error (the cause) which happened during the json unmarshalling.

func (*JsonValidationError) ContainsLineInformation added in v1.1.0

func (e *JsonValidationError) ContainsLineInformation() bool

ContainsLineInformation indicates whether additional line information is present in the error.

func (JsonValidationError) Error added in v1.1.0

func (e JsonValidationError) Error() string

func (*JsonValidationError) PrettyPrintError added in v1.1.0

func (e *JsonValidationError) PrettyPrintError()

type Template

type Template interface {
	ExecuteTemplate(data map[string]string) (string, error)
}

Template wraps the underlying templating logic and provides a means of setting config values just on one place. It is intended to be language-agnostic, the file type does not matter (yaml, json, ...)

func NewTemplate

func NewTemplate(fs afero.Fs, fileName string) (Template, error)

NewTemplate creates a new template for the given file

func NewTemplateFromString

func NewTemplateFromString(name string, content string) (Template, error)

NewTemplateFromString creates a new template for the given string content

type TimelineProvider added in v1.1.0

type TimelineProvider interface {

	// Now Returns the current (client-side) time in UTC
	Now() time.Time

	// Sleep suspends the current goroutine for the specified duration
	Sleep(duration time.Duration)
}

TimelineProvider abstracts away the time.Now() and time.Sleep(time.Duration) functions to make code unit-testable Whenever you need to get the current time, or want to pause the current goroutine (sleep), please consider using this interface

func NewTimelineProvider added in v1.1.0

func NewTimelineProvider() TimelineProvider

NewTimelineProvider creates a new TimelineProvider

Jump to

Keyboard shortcuts

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