util

package
v0.16.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: Apache-2.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidRange = errors.New("Invalid byte range provided for file")
)

Functions

func GetEnvOrDefault added in v0.14.0

func GetEnvOrDefault[T any](key string, defaultVal T, conversionFunc func(string) (T, error)) T

GetEnvOrDefault returns an environment variable or a default if either the environment variable does not exist or fails to parse using the specified conversionFunc function

func IsAppleSiliconMac added in v0.8.0

func IsAppleSiliconMac(goos string, goarch string) bool

IsAppleSiliconMac returns whether the current machine is an Apple silicon computer, such as the MacBook Air with M1.

func PickFreePort added in v0.14.11

func PickFreePort(minPort, maxPort int) (int, error)

PickFreePort returns a TCP port in [min,max] that's not in use on the 127.0.0.1 interface. Note that there's a small chance of a race condition when a port is considered free at the time of the call, but not free when something tries to use it. This is good enough for dev and test code though.

func SHA256HashFile added in v0.14.0

func SHA256HashFile(path string) (string, error)

func SHA256HashFileWithSaltAndRange added in v0.14.0

func SHA256HashFileWithSaltAndRange(path string, start int, end int, salt string) (string, error)

func WrapError added in v0.14.0

func WrapError(err error, message string) error

WrapError is just a shortcut for using fmt.Errorf to wrap an error with a message

Types

type RingBufferWriter added in v0.14.8

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

RingBufferWriter is a writer that writes to an underlying writer and also maintains a ring buffer of the last N bytes written.

func NewRingBufferWriter added in v0.14.8

func NewRingBufferWriter(w io.Writer, size int) *RingBufferWriter

NewRingBufferWriter creates a new RingBufferWriter that writes to w and maintains a buffer of the last size bytes.

func (*RingBufferWriter) String added in v0.14.8

func (w *RingBufferWriter) String() string

String returns the contents of the ring buffer as a string

func (*RingBufferWriter) Write added in v0.14.8

func (w *RingBufferWriter) Write(p []byte) (n int, err error)

Write implements io.Writer interface

Directories

Path Synopsis
Package console provides a standard interface for user- and machine-interface with the console
Package console provides a standard interface for user- and machine-interface with the console

Jump to

Keyboard shortcuts

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