Documentation ¶
Index ¶
- Variables
- func CheckError(err error, msg string) bool
- func CheckProperty(properties map[string]string, property string) (string, error)
- func ConvertMicrosecondsToUnixTime(timeInMicroseconds int64) time.Time
- func FailOnError(err error, msg string)
- func IsRequestLoggingActive() bool
- func IsResponseLoggingActive() bool
- func LogRequest(id string, request *http.Request) error
- func LogResponse(id string, response *http.Response) error
- func PrintError(err error)
- func PrintErrors(errors []error)
- func ReplacePathSeparators(path string) (newPath string)
- func SetupLogging(verbose bool) error
- func StringTimestampToHumanReadableFormat(unixTimestampAsString string) (humanReadable string, parsedTimestamp int64, err error)
- func UnmarshalYaml(text string, fileName string) (error, map[string]map[string]string)
- func ValidateAndParseJson(jsonString string, filename string) (map[string]interface{}, error)
- type FileReader
- type JsonValidationError
- type Template
- type TimelineProvider
Constants ¶
This section is empty.
Variables ¶
var Log lumber.Logger = lumber.NewConsoleLogger(lumber.INFO)
Log is the shared Lumber Logger logging to console and after calling SetupLogging also to file
Functions ¶
func CheckError ¶
func CheckProperty ¶
func ConvertMicrosecondsToUnixTime ¶ added in v1.1.0
ConvertMicrosecondsToUnixTime converts the UTC time in microseconds to a time.Time struct (unix time)
func FailOnError ¶
func IsRequestLoggingActive ¶ added in v1.3.0
func IsRequestLoggingActive() bool
func IsResponseLoggingActive ¶ added in v1.5.0
func IsResponseLoggingActive() bool
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 SetupLogging ¶
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 ¶
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
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.
Types ¶
type FileReader ¶
type FileReader interface { ReadFile(fileName string) (content []byte, err error) ReadDir(fileName string) ([]os.FileInfo, error) }
A FileReader is an interface which encapsulates io/ioutil to make the code using it testable. Since the reading of the file is now behind an interface, we can easily mock it.
func NewFileReader ¶
func NewFileReader() FileReader
NewFileReader creates a new FileReader. A FileReader is an interface which encapsulates io/ioutil to make the code using it testable. Since the reading of the file is now behind an interface, we can easily mock it.
func NewInMemoryFileReader ¶
func NewInMemoryFileReader(originalDir string, transformers []func(string) string) (FileReader, error)
NewInMemoryFileReader creates a new in-memory file reader which reads all the original files once and stores them internally in-memory. This allows us to perform any modifications on the files later on
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 ¶
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 ¶
NewTemplate creates a new template for the given file
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