sys

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2025 License: MIT Imports: 17 Imported by: 0

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 URL is localhost or 127.0.0.1 or 0.0.0.0.

func IsRunningInsideDocker

func IsRunningInsideDocker() bool

IsRunningInsideDocker returns true if the process is running inside a docker container.

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 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

Jump to

Keyboard shortcuts

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