util

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: BSD-3-Clause Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LogConsole = "console"
	LogSyslog  = "syslog"
)

Variables

View Source
var (
	SpecialLogs = []string{
		LogSyslog,
		LogConsole,
	}
)

Functions

func AddSyslogHook

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

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

func EnforcePermission(dirPath string) error

func False

func False() *bool

False returns a *bool whose underlying value is false.

func FileExists

func FileExists(path string) bool

FileExists returns true if specified file exists

func FindFirstLogPath

func FindFirstLogPath(logs []string) string

FindFirstLogPath returns the first logs entry that could be a log path, that is neither empty, nor a special value

func GetCallerName

func GetCallerName() string

func InitLog

func InitLog(logLevel string, logs ...string) error

InitLog parses and sets log-level input

func IsAdmin

func IsAdmin() bool

IsAdmin returns true if user is root

func ListFiles

func ListFiles(dir, pattern string) ([]string, error)

ListFiles returns the full paths of all files in dir that match pattern. Pattern uses shell-style globbing (e.g. "*.json").

func OpenBrowser added in v0.2.0

func OpenBrowser(url string) error

OpenBrowser opens the URL in a browser, respecting the BROWSER environment variable.

func ReadJson

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

ReadJson reads JSON config file and maps to a provided interface

func ReadJsonWithEnvSub

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

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

func RemoveJson

func RemoveJson(file string) error

RemoveJson removes the specified JSON file if it exists

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

func ReturnBoolWithDefaultFalse(b *bool) bool

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

func ReturnBoolWithDefaultTrue

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

func True() *bool

True returns a *bool whose underlying value is true.

func WriteBytesWithRestrictedPermission

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

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