utils

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DateFormat = "2006-01-02"

DateFormat is the standard date format used throughout the code.

Variables

This section is empty.

Functions

func CreateDir

func CreateDir(path string) error

CreateDir creates a new directory in the file system.

func DeleteDir

func DeleteDir(path string) error

DeleteDir deletes a directory

func HomeDir

func HomeDir() string

HomeDir returns the current user's home directory

func NewFile

func NewFile(fileName string) (*os.File, error)

NewFile creates a new file

func PathExists

func PathExists(path string) (bool, error)

PathExists returns true whether the path exists or not in the file system

func SecondsToHuman

func SecondsToHuman(input int) (result string)

SecondsToHuman returns a human description of a duration in seconds Taken from: https://www.socketloop.com/tutorials/golang-convert-seconds-to-human-readable-time-format-example

func TimeToStandardDateTimeFormat

func TimeToStandardDateTimeFormat(time time.Time) string

func WriteToFile

func WriteToFile(fileName string, bytes []byte) error

WriteToFile writes bytes to a file.

Types

type Clock

type Clock interface {
	Now() time.Time
	SetNow(time.Time) error
}

Clock is a general interface to control the time.

type LiveClock

type LiveClock struct{}

LiveClock represents a "correct" clock (time has not been tempered with)

func NewLiveClock

func NewLiveClock() *LiveClock

NewClickClock returns a new, correct, clock

func (LiveClock) Now

func (clock LiveClock) Now() time.Time

Now returns the current time in the correct clock

func (LiveClock) SetNow

func (clock LiveClock) SetNow(time time.Time) error

SetNow will not work on a "correct" clock, since it's always moving forwards

type MockedClock

type MockedClock struct {
	MockedNow time.Time
}

MockedClock represents a clock where the current time is changed

func NewMockedClock

func NewMockedClock(now time.Time) *MockedClock

NewMockedClock returns a new mocked clock

func (*MockedClock) Now

func (clock *MockedClock) Now() time.Time

Now returns the current time in the mocked clock

func (*MockedClock) SetNow

func (clock *MockedClock) SetNow(time time.Time) error

SetNow changes the current time in the mocked clock

type NotFoundError

type NotFoundError struct {
	Err string
}

NotFoundError represents the specific error NotFound (useful when something cannot be found, like an activity)

func NewNotFoundError

func NewNotFoundError(err string) *NotFoundError

NewNotFoundError creates a new not found error

func (*NotFoundError) Error

func (err *NotFoundError) Error() string

Error implements the Error method from the error interface

type ReportNotImplementedError

type ReportNotImplementedError struct {
	Err string
}

func NewReportNotImplementedError

func NewReportNotImplementedError() *ReportNotImplementedError

NewReportNotImplementedError creates a new not found error

func (*ReportNotImplementedError) Error

func (err *ReportNotImplementedError) Error() string

Jump to

Keyboard shortcuts

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