util

package
v0.34.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: BSD-3-Clause Imports: 19 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSyslogHook added in v0.28.5

func AddSyslogHook()

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(ctx context.Context, file string, obj interface{}) error

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

func EnforcePermission added in v0.29.3

func EnforcePermission(dirPath string) error

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

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

ReadJsonWithEnvSub reads JSON config file and maps to a provided interface with environment variable substitution

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

func WriteBytesWithRestrictedPermission(ctx context.Context, file string, bs []byte) error

func WriteJson

func WriteJson(ctx context.Context, file string, obj interface{}) error

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

func WriteJsonWithRestrictedPermission added in v0.29.3

func WriteJsonWithRestrictedPermission(ctx context.Context, file string, obj interface{}) error

WriteJsonWithRestrictedPermission writes JSON config object to a file. Enforces permission on the parent directory

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