util

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: MIT Imports: 14 Imported by: 18

Documentation

Index

Constants

View Source
const (
	SecInMinute = 60
	MinInHour   = 60
	HoursInDay  = 8
	DaysInWeek  = 5
)

Variables

Debug is no-op implementation of the debug logger

View Source
var Now = func() time.Time { return time.Now() }

Now is the func used for system time within gtm This allows for manipulating system time during testing

View Source
var (
	// Profile is a no-op implemention of the profile logger
	Profile = func(s ...string) func() {
		return func() {
		}
	}
)

Functions

func CheckFatal

func CheckFatal(t *testing.T, err error)

CheckFatal raises a fatal error if error is not nil

func DurationStr

func DurationStr(secs int) string

DurationStr returns seconds as a duration string, i.e. 9h10m30s

func DurationStrJira added in v1.0.0

func DurationStrJira(secs int) string

DurationStrJira returns seconds as duration string, i.e. 1d 9h 10m

func DurationStrLong

func DurationStrLong(secs int) string

DurationStrLong returns a human readable format for the duration

func FormatDuration

func FormatDuration(secs int) string

FormatDuration converts seconds into a duration string

func LeftPad2Len

func LeftPad2Len(s string, padStr string, overallLen int) string

LeftPad2Len https://github.com/DaddyOh/golang-samples/blob/master/pad.go

func Map

func Map(vs []string, f func(string) string) []string

Map applys a func to a string array

func Percent

func Percent(val, total int) float64

Percent returns a values percent of the total

func RightPad2Len

func RightPad2Len(s string, padStr string, overallLen int) string

RightPad2Len https://github.com/DaddyOh/golang-samples/blob/master/pad.go

func UcFirst

func UcFirst(str string) string

UcFirst Uppercase first letter

Types

type ByInt64

type ByInt64 []int64

ByInt64 list of type int64

func (ByInt64) Len

func (e ByInt64) Len() int

func (ByInt64) Less

func (e ByInt64) Less(i, j int) bool

func (ByInt64) Swap

func (e ByInt64) Swap(i, j int)

type CallFrame

type CallFrame struct {
	File     string
	Line     int
	Function string
}

CallFrame contains the file, line number and function

func (CallFrame) String

func (c CallFrame) String() string

String returns a canonical representation of a CallFrame

type ContextLogger

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

ContextLogger adds child and parent file location to logging

func NewContextLogger

func NewContextLogger(x *log.Logger, skip int) *ContextLogger

NewContextLogger initializes a ContextLogger struct

func (*ContextLogger) Print

func (c *ContextLogger) Print(v ...interface{})

Print prints log message with context

func (*ContextLogger) Printf

func (c *ContextLogger) Printf(format string, v ...interface{})

Printf prints log message with context and format

func (*ContextLogger) Println

func (c *ContextLogger) Println(v ...interface{})

Println prints log message with context

type DateRange

type DateRange struct {
	Start time.Time
	End   time.Time
}

DateRange creates predefined date ranges and validates if dates are within the range

func AfterNow

func AfterNow(n int) DateRange

AfterNow returns a date range ending n days in the past

func LastMonthRange

func LastMonthRange() DateRange

LastMonthRange returns a date range for last month

func LastWeekRange

func LastWeekRange() DateRange

LastWeekRange returns a date for last week

func LastYearRange

func LastYearRange() DateRange

LastYearRange returns a date range for last year

func ThisMonthRange

func ThisMonthRange() DateRange

ThisMonthRange returns a date range for this month

func ThisWeekRange

func ThisWeekRange() DateRange

ThisWeekRange returns a date range for this week

func ThisYearRange

func ThisYearRange() DateRange

ThisYearRange returns a date range for this year

func TodayRange

func TodayRange() DateRange

TodayRange returns a date range for today

func YesterdayRange

func YesterdayRange() DateRange

YesterdayRange returns a date range for yesterday

func (DateRange) IsSet

func (d DateRange) IsSet() bool

IsSet returns true if the date range has a starting and/or ending date

func (DateRange) String

func (d DateRange) String() string

String returns a date range as a string

func (DateRange) Within

func (d DateRange) Within(t time.Time) bool

Within determines if a date is within the date range

type FamilyCallStack

type FamilyCallStack struct {
	Parent CallFrame
	Child  CallFrame
}

FamilyCallStack contains the child and parent call frames

func NewFamilyCallStack

func NewFamilyCallStack(f *runtime.Frames) FamilyCallStack

NewFamilyCallStack initializes a FamilyCallStack struct

func (FamilyCallStack) String

func (f FamilyCallStack) String() string

String returns a canonical representation of a FamilyCallStack

type TestRepo

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

TestRepo represents a test git repo used in testing

func NewTestRepo

func NewTestRepo(t *testing.T, bare bool) TestRepo

NewTestRepo creates a new instance of TestRepo

func (TestRepo) AddSubmodule

func (t TestRepo) AddSubmodule(url, path string)

AddSubmodule adds a submodule to the test repository

func (TestRepo) Clone

func (t TestRepo) Clone() TestRepo

Clone creates a clone of this repo

func (TestRepo) Commit

func (t TestRepo) Commit(treeID *git.Oid) *git.Oid

Commit commits staged files

func (TestRepo) Fetch

func (t TestRepo) Fetch(name string, refs ...string)

Fetch refs from remote

func (TestRepo) FileExists

func (t TestRepo) FileExists(filename, subdir string) bool

FileExists Checks if a file exists in the repo folder

func (TestRepo) Path

func (t TestRepo) Path() string

Path return the git path for the git repository

func (TestRepo) Push

func (t TestRepo) Push(name string, refs ...string)

Push to remote refs to remote

func (TestRepo) Remove

func (t TestRepo) Remove()

Remove deletes temp directories, files and git repo

func (TestRepo) Repo

func (t TestRepo) Repo() *git.Repository

Repo return a pointer to the git repository

func (TestRepo) SaveFile

func (t TestRepo) SaveFile(filename, subdir, content string)

SaveFile creates a file within the git repo project

func (TestRepo) Seed

func (t TestRepo) Seed()

Seed creates test data for the git repo

func (TestRepo) Stage

func (t TestRepo) Stage(files ...string) *git.Oid

Stage adds files to staging for git repo

func (TestRepo) Workdir

func (t TestRepo) Workdir() string

Workdir return the working directory for the git repository

Jump to

Keyboard shortcuts

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