sys

package
v1.0.138 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2026 License: MIT Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyDir

func CopyDir(src string, dst string) error

CopyDir will copy all files recursively from src to dst

func CopyFile

func CopyFile(src, dst string) (int64, error)

CopyFile will copy src to dst

func CreateShutdownChannel

func CreateShutdownChannel() chan os.Signal

CreateShutdownChannel returns a channel which can be used to block for a termination signal (SIGTERM, SIGINT, etc)

func Exists

func Exists(fn string) bool

Exists returns true if the filename or directory specified by fn exists.

func GetFreePort

func GetFreePort() (port int, err error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GzipFile

func GzipFile(filepath string) error

GzipFile compresses a file using gzip.

func IsLocalhost

func IsLocalhost(url string) bool

IsLocalhost returns true if the input points to localhost/loopback or an unspecified address.

func IsRunningInsideContainer added in v1.0.110

func IsRunningInsideContainer() bool

IsRunningInsideContainer returns true if the process is running inside a container environment.

func IsRunningInsideDocker

func IsRunningInsideDocker() bool

IsRunningInsideDocker returns true if the process is running inside a container environment. WARNING: This function is deprecated and will be removed in a future release.

func ListDir

func ListDir(dir string) ([]string, error)

ListDir will return an array of files recursively walking into sub directories

func LocalIP

func LocalIP() (string, error)

LocalIP will return the local ipaddress for the machine

func ProcessDirWithDecoder

func ProcessDirWithDecoder(dir string, callback ProcessDirWithDecoderCallback) error

ProcessDirWithDecoder will process all the JSON files in directory and call the callback

func Ptr added in v1.0.79

func Ptr[T any](v T) *T

Ptr returns a pointer to the given value.

func RecoverPanic

func RecoverPanic(logger logger.Logger)

RecoverPanic recovers from a panic and logs the error along with the current goroutines.

func TarGz

func TarGz(srcDir string, outfile *os.File) error

func Unzip

func Unzip(src, dest string, flatten bool) error

Unzip a file to a directory

func WriteJSON

func WriteJSON(filename string, v any) error

func WriteJSONLAppend

func WriteJSONLAppend(filename string, v []interface{}) error

Types

type JSONDecoder

type JSONDecoder interface {
	Decode(v any) error
	// More returns true if there are more items in the stream
	More() bool
	// Count returns the number of records read
	Count() int
	// Close a stream
	Close() error
}

func NewNDJSONDecoder

func NewNDJSONDecoder(fn string) (JSONDecoder, error)

NewNDJSONDecoder returns a decoder which can be used to read JSON new line delimited files

type JSONEncoder

type JSONEncoder interface {
	// Encode will encode v as a new line delimited JSON encoded string
	Encode(v any) error
	// Close a stream
	Close() error
	// Count returns the number of records written
	Count() int
}

JSONEncoder is an encoder that will allow you to encode one or more objects as JSON newline delimited output

func NewNDJSONEncoder

func NewNDJSONEncoder(fn string) (JSONEncoder, error)

NewNDJSONEncoder will return a JSONEncoder which allows you to stream json as new line delimited JSON

func NewNDJSONEncoderAppend

func NewNDJSONEncoderAppend(fn string) (JSONEncoder, error)

type ProcessDirWithDecoderCallback

type ProcessDirWithDecoderCallback func(decoder JSONDecoder, filename string) error

type Result added in v1.0.79

type Result[T any] struct {
	Ok  T
	Err error
}

Result represents a value that can be either successful (Ok) or an error (Err), similar to Rust's Result type.

func Err added in v1.0.79

func Err[T any](err error) Result[T]

Err creates a new Result with an error.

func Ok added in v1.0.79

func Ok[T any](value T) Result[T]

Ok creates a new Result with a successful value.

func (Result[T]) IsErr added in v1.0.79

func (r Result[T]) IsErr(checks ...error) bool

IsErr returns true if the Result contains an error.

func (Result[T]) IsErrMatches added in v1.0.79

func (r Result[T]) IsErrMatches(checks ...string) bool

IsErrMatches returns true if the Result contains an error containing any of the given string values.

func (Result[T]) IsOk added in v1.0.79

func (r Result[T]) IsOk() bool

IsOk returns true if the Result contains a successful value (no error).

Jump to

Keyboard shortcuts

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