util

package
v0.0.0-...-b9641ee Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeHash

func ComputeHash(s string) string

func DoesPathExist

func DoesPathExist(path string) bool

DoesPathExist determines if a specific file or directory path exists or not

func IsDirectory

func IsDirectory(path string) bool

IsDirectory determines if a file represented by `path` is a directory or not

func IsFile

func IsFile(path string) bool

IsFile determines if a file represented by `path` is a regular file or not

func NormalizePath

func NormalizePath(path string) string

NormalizePath handles any path updates necessary for standard path resolution:

func ToJSON

func ToJSON(data any) string

JSONString returns a JSON string representation of the given data. This is intended for use in debugging easily (e.g. `log.Debugf("received: %s", to.JSONString(body))`), and so returns one string. Since this has no errors, we make efforts to return reasonable values that are always legal JSON strings: - If input is nil {} - If data is an error, a string representation of the error "error message" - If data cannot be marshalled, a "%#v" string representation of the data "main.T{b:true, i:42, s:[]string{\"life\", \"universe\", \"everything\"}}" - Otherwise, the JSON representation of the data (no private fields, etc)

Types

type IndentingReport

type IndentingReport struct {
	Level ReportLevel // true to print to stderr, false to log
	Size  int         // total number of report lines printed (not including section headers)
	// contains filtered or unexported fields
}

IndentingReport manages printing out a report with indents. Every time you start a section, the indent will be increased, and when you end a section the indent will be decreased. Sections titles are not printed unless there is something under them. So you can start a section whenever you want, defer the end of the section, and if nothing gets printed in the meantime, then nothing about the section will ever be printed

func NewIndentingReport

func NewIndentingReport(level ReportLevel) *IndentingReport

func (*IndentingReport) Printf

func (r *IndentingReport) Printf(format string, a ...interface{})

Prints a report line to the appropriate output channel

func (*IndentingReport) StartSection

func (r *IndentingReport) StartSection(title string)

StartSection starts a new section in the report by printing a title and indenting subsequent output by one level. The section title is not printed unless there is actually something to print under it though

func (*IndentingReport) StopSection

func (r *IndentingReport) StopSection()

StopSection stops a section by reducing the indent on subsequent output

func (*IndentingReport) String

func (r *IndentingReport) String() string

String returns the cached report as a string

type ReportLevel

type ReportLevel string
const (
	ReportSilent ReportLevel = "silent" // do not write the report anywhere (get it later with String())
	ReportLog    ReportLevel = "log"    // write the report to the log
	ReportErr    ReportLevel = "err"    // write the report to stderr
	ReportOut    ReportLevel = "out"    // write the report to stdout
)

type StopWatch

type StopWatch struct {
	StartTime time.Time
	StopTime  time.Time
}

func NewStopWatch

func NewStopWatch() StopWatch

func (StopWatch) Elapsed

func (w StopWatch) Elapsed() time.Duration

Elapsed returns either the duration since the watch was started (if it hasn't been stopped yet), or the duration between start and stop (if it is stopped)

func (*StopWatch) Start

func (w *StopWatch) Start()

Start starts (or restarts) the stopwatch, clearing the stop time

func (*StopWatch) Stop

func (w *StopWatch) Stop() time.Duration

Stop stops the stopwatch and returns the amount of time it's been running

Jump to

Keyboard shortcuts

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