utils

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	VCSDirs        *Set
	GitIgnore      *ignore.GitIgnore
	CurrentRootDir string
)

Functions

func AnalyzeTimeConsumed added in v0.1.5

func AnalyzeTimeConsumed() func()

AnalyzeTimeConsumed is a function that returns a function that can be used to analyze the time consumed. Usage: defer AnalyzeTimeConsumed()()

func AssertEqual added in v0.1.5

func AssertEqual(t *testing.T, actual any, expected any)

func AssertNot added in v0.1.5

func AssertNot(t *testing.T, actual any, expected any)

func CaptureStdout added in v0.1.5

func CaptureStdout(fn func()) string

CaptureStdout captures the output of a function that writes to stdout and returns the output content as a string

func ErrorMsg added in v0.1.6

func ErrorMsg(format string, a ...any)

func Fail added in v0.1.6

func Fail(t *testing.T, expected any, actual any)

func ShouldIgnoreFile added in v0.1.7

func ShouldIgnoreFile(cutRootDirPath string) bool

func StartCPUProfile

func StartCPUProfile() func()

You can view the cpu profile file with `go tool pprof codetalks-cpu.prof` or visualize it on website like https://www.speedscope.app/

func StartMemoryProfile

func StartMemoryProfile() func()

You can view the memory profile file with `go tool pprof codetalks-mem.prof` or visualize it on website like https://www.speedscope.app/

func StartTrace

func StartTrace() func()

You can view the trace file with `go tool trace codetalks-trace.prof`

func TimeIt

func TimeIt(fn func(), task string)

func WalkDir added in v0.1.7

func WalkDir(root string, fn fs.WalkDirFunc) error

WalkDir walks the file tree rooted at root, calling fn for each file or directory in the tree, including root.

All errors that arise visiting files and directories are filtered by fn: see the fs.WalkDirFunc documentation for details.

The files are walked in lexical order, which makes the output deterministic but requires WalkDir to read an entire directory into memory before proceeding to walk that directory.

WalkDir does not follow symbolic links.

WalkDir calls fn with paths that use the separator character appropriate for the operating system. This is unlike io/fs.WalkDir, which always uses slash separated paths.

func WithTimeoutCtxMilliSeconds added in v0.1.6

func WithTimeoutCtxMilliSeconds(milliSeconds int) (context.Context, context.CancelFunc)

func WithTimeoutCtxSeconds added in v0.1.6

func WithTimeoutCtxSeconds(seconds int) (context.Context, context.CancelFunc)

Types

type Set

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

Define a set as a map with keys of type string and values of type void

func NewSet

func NewSet() *Set

Helper function to create a new set

func (*Set) Add

func (s *Set) Add(item string)

Helper function to add an item to the set

func (*Set) Contains

func (s *Set) Contains(item string) bool

Helper function to check if an item is in the set

func (*Set) Items added in v0.1.5

func (s *Set) Items() []string

Debug purpose: Helper function to get all items in the set

func (*Set) Len added in v0.1.5

func (s *Set) Len() int

Debug purpose: Helper function to get the number of items in the set

func (*Set) Remove

func (s *Set) Remove(item string)

Helper function to remove an item from the set

Jump to

Keyboard shortcuts

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