helper

package module
v0.0.0-...-51a25f5 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 18 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//Debug variable to toggle debug output
	Debug bool
	//Verbose variable to toggle verbose output
	Verbose       bool
	Info          bool
	InfoTimestamp bool
	WarnExit      bool
	FatalExit     bool
	Quiet         bool
)

Functions

func BoolPointer

func BoolPointer(b bool) *bool

func CheckDirAndCreate

func CheckDirAndCreate(dir string, name string) (string, error)

checkDirAndCreate tests if the given directory exists and tries to create it

func CreateOrPurgeDir

func CreateOrPurgeDir(dir string, callingFunction string)

func Debugf

func Debugf(s string)

Debugf is a helper function for Debug logging if global variable Debug is set to true

func DetectBrowserOrCLI

func DetectBrowserOrCLI(request *http.Request) string

DetectBrowserOrCLI checks for the existance of a User-Agent request header and primitivly tries to check if the request was made from a browser or from a CLI, like wget or curl and returns either "plain" if a CLI was detected or "html" if a browser was detected

func Fatalf

func Fatalf(s string)

Fatalf is a helper function for fatal logging

func FileExists

func FileExists(file string) bool

FileExists checks if the given file exists and returns a bool

func FuncName

func FuncName() string

funcName return the function name as a string

func GetRequestClientIp

func GetRequestClientIp(request *http.Request, proxyNetworks []net.IPNet) (net.IP, error)

GetRequestClientIp extract the client IP address from the request with support for X-Forwarded-For header when the request is originating from proxied networks

func GetSha256sumFile

func GetSha256sumFile(file string) string

getSha256sumFile return the SHA256 hash sum of the given file

func InBetween

func InBetween(i, min, max int) bool

func Infof

func Infof(s string)

Infof is a helper function for Info logging if global variable Info is set to true

func IsDir

func IsDir(dir string) bool

isDir checks if the given dir exists and returns a bool

func KeysString

func KeysString(m map[string]struct{}) []string

func NormalizeDir

func NormalizeDir(dir string) string

NormalizeDir removes from the given directory path multiple redundant slashes and adds a trailing slash

func ParseNetworks

func ParseNetworks(networkStrings []string, contextMessage string) ([]net.IPNet, error)

func PurgeDir

func PurgeDir(dir string, callingFunction string)

func RandSeq

func RandSeq() string

randSeq returns a fixed length random string to identify each request in the log http://stackoverflow.com/a/22892986/682847

func StringSliceContains

func StringSliceContains(slice []string, element string) bool

func TimeTrack

func TimeTrack(start time.Time, name string)

func Verbosef

func Verbosef(s string)

Verbosef is a helper function for Verbose logging if global variable Verbose is set to true

func Warnf

func Warnf(s string)

Warnf is a helper function for warning logging

func WriteStructJSONFile

func WriteStructJSONFile(file string, v interface{})

Types

type ExecResult

type ExecResult struct {
	ReturnCode int
	Output     string
}

ExecResult contains the exit code and output of an external command (e.g. git)

func ExecuteCommand

func ExecuteCommand(command string, timeout int, allowFail bool) ExecResult

Jump to

Keyboard shortcuts

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