util

package
v0.0.0-...-93fed14 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFileContents

func CopyFileContents(src, dst string) (err error)

CopyFileContents copies contents of the given src file to the dst file

func DirectWriteJson

func DirectWriteJson(file string, obj interface{}) error

DirectWriteJson writes JSON config object to a file creating parent directories if required without creating a temporary file

func FileExists

func FileExists(path string) bool

FileExists returns true if specified file exists

func InitLog

func InitLog(logLevel string, logPath string) error

InitLog parses and sets log-level input

func IsAdmin

func IsAdmin() bool

IsAdmin returns true if user is root

func ReadJson

func ReadJson(file string, res interface{}) (interface{}, error)

ReadJson reads JSON config file and maps to a provided interface

func Retry

func Retry(attempts int, sleep time.Duration, toExec func() error, onError func(e error)) error

Retry retries a given toExec function calling onError on failed attempts onError shouldn be a lightweight function and shouldn't be blocking

func SliceDiff

func SliceDiff(x, y []string) []string

SliceDiff returns the elements in slice `x` that are not in slice `y`

func WriteJson

func WriteJson(file string, obj interface{}) error

WriteJson writes JSON config object to a file creating parent directories if required The output JSON is pretty-formatted

Types

type Duration

type Duration struct {
	time.Duration
}

Duration is used strictly for JSON requests/responses due to duration marshalling issues

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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