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 LogRequest(url string, method string, content string) error
- func PrettyPrintError(err 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 MockFileReader
- type MockFileReaderMockRecorder
- type MockTimelineProvider
- type MockTimelineProviderMockRecorder
- 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 PrettyPrintError ¶ added in v1.1.0
func PrettyPrintError(err error)
PrettyPrintError should pretty-print the error using a more user-friendly format In the future, this will be extended to support various more errors.
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 MockFileReader ¶
type MockFileReader struct {
// contains filtered or unexported fields
}
MockFileReader is a mock of FileReader interface
func NewMockFileReader ¶
func NewMockFileReader(ctrl *gomock.Controller) *MockFileReader
NewMockFileReader creates a new mock instance
func (*MockFileReader) EXPECT ¶
func (_m *MockFileReader) EXPECT() *MockFileReaderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockFileReaderMockRecorder ¶
type MockFileReaderMockRecorder struct {
// contains filtered or unexported fields
}
MockFileReaderMockRecorder is the mock recorder for MockFileReader
func (*MockFileReaderMockRecorder) ReadDir ¶
func (_mr *MockFileReaderMockRecorder) ReadDir(arg0 interface{}) *gomock.Call
ReadDir indicates an expected call of ReadDir
func (*MockFileReaderMockRecorder) ReadFile ¶
func (_mr *MockFileReaderMockRecorder) ReadFile(arg0 interface{}) *gomock.Call
ReadFile indicates an expected call of ReadFile
type MockTimelineProvider ¶ added in v1.1.0
type MockTimelineProvider struct {
// contains filtered or unexported fields
}
MockTimelineProvider is a mock of TimelineProvider interface
func NewMockTimelineProvider ¶ added in v1.1.0
func NewMockTimelineProvider(ctrl *gomock.Controller) *MockTimelineProvider
NewMockTimelineProvider creates a new mock instance
func (*MockTimelineProvider) EXPECT ¶ added in v1.1.0
func (_m *MockTimelineProvider) EXPECT() *MockTimelineProviderMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
func (*MockTimelineProvider) Now ¶ added in v1.1.0
func (_m *MockTimelineProvider) Now() time.Time
Now mocks base method
func (*MockTimelineProvider) Sleep ¶ added in v1.1.0
func (_m *MockTimelineProvider) Sleep(duration time.Duration)
Sleep mocks base method
type MockTimelineProviderMockRecorder ¶ added in v1.1.0
type MockTimelineProviderMockRecorder struct {
// contains filtered or unexported fields
}
MockTimelineProviderMockRecorder is the mock recorder for MockTimelineProvider
func (*MockTimelineProviderMockRecorder) Now ¶ added in v1.1.0
func (_mr *MockTimelineProviderMockRecorder) Now() *gomock.Call
Now indicates an expected call of Now
func (*MockTimelineProviderMockRecorder) Sleep ¶ added in v1.1.0
func (_mr *MockTimelineProviderMockRecorder) Sleep(arg0 interface{}) *gomock.Call
Sleep indicates an expected call of Sleep
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