util

package
v0.27.7 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: BSD-3-Clause Imports: 10 Imported by: 6

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 added in v0.23.3

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 False added in v0.26.0

func False() *bool

False returns a *bool whose underlying value is false.

func FileExists added in v0.8.1

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 added in v0.8.0

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 ReturnBoolWithDefaultFalse added in v0.26.0

func ReturnBoolWithDefaultFalse(b *bool) bool

Return bool representation if the bool pointer is non-nil, otherwise returns false

func ReturnBoolWithDefaultTrue added in v0.26.0

func ReturnBoolWithDefaultTrue(b *bool) bool

Return bool representation if the bool pointer is non-nil, otherwise returns true

func SliceDiff

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

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

func True added in v0.26.0

func True() *bool

True returns a *bool whose underlying value is true.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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