common

package
v0.0.30 Latest Latest
Warning

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

Go to latest
Published: May 11, 2020 License: GPL-3.0 Imports: 19 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LogDebug   *log.Logger = log.New(os.Stderr, "Debug ", log.LstdFlags)
	LogTrace   *log.Logger = log.New(os.Stderr, "Trace ", log.LstdFlags)
	LogInfo    *log.Logger = log.New(os.Stderr, "Info ", log.LstdFlags)
	LogWarning *log.Logger = log.New(os.Stderr, "Warning ", log.LstdFlags)
	LogError   *log.Logger = log.New(os.Stderr, "Error ", log.LstdFlags)
)

Functions

func Abort

func Abort(err error)

Abort does nothing if err is nil, otherwise logs the error and exits

func AbortWithString

func AbortWithString(msg string)

func BigEndianUint32

func BigEndianUint32(val uint32) []byte

func BigEndianUint64

func BigEndianUint64(val int64) []byte

func BoolFromQuery

func BoolFromQuery(name string, r *http.Request) bool

BoolFromQuery return false if query is missing or set to false

func BytesToString

func BytesToString(data []byte) string

func CRC32

func CRC32(input []byte) []byte

func CloneStringSlice

func CloneStringSlice(a []string) []string

func Contains

func Contains(target string, list []string) bool

func CreateFile

func CreateFile(fullPath string) (*os.File, error)

func DefaultToExecutable

func DefaultToExecutable(path string) string

Default to executable returns full path. If input path is relative, it will considered relative to the the folder of the executable

func DirSize

func DirSize(path string) (int64, error)

DirSize returns the size the files in a folder and subfolders in bytes

func DivideRoundUp

func DivideRoundUp(numerator, divisor uint64) uint64

func DownloadFile

func DownloadFile(w io.Writer, url string) error

DownloadFile will download a file from a url. Assumes that url is a file download url

func EraseInt

func EraseInt(a []int, x int) []int

func EraseString

func EraseString(a []string, x string) []string

func ExtendedSliceToMultipleOf

func ExtendedSliceToMultipleOf(multiple int, input []byte) []byte

func FileExists

func FileExists(path string) bool

func FileSize

func FileSize(path string) int64

func FileSizeString

func FileSizeString(fullPath string) string

func GetTempFile

func GetTempFile() (f *os.File, err error)

func I64ToA

func I64ToA(i int64) string

func InitLogging

func InitLogging(filePath string)

InitLogging initializes a rotating logger. This should be done once by the executable filePath is the full path of the log file

func InvalidArgs

func InvalidArgs(msg string)

func IsFullPath

func IsFullPath(path string) bool

func IsLegalFilePath

func IsLegalFilePath(path string) error

IsLegalFilePath checks for forbidden characters

func IsLegalUserName

func IsLegalUserName(userName string) error

IsLegalUserName checks for forbidden characters

func Join

func Join(dir, subpath string) string

func MakeFolders

func MakeFolders(folders []string) (err error)

func MakeStringOfLen

func MakeStringOfLen(length int) string

func Max

func Max(x, y int) int

Max returns the larger of x or y.

func Min

func Min(x, y int) int

Min returns the smaller of x or y.

func NeedArgs

func NeedArgs(arg string)

func NumLines

func NumLines(r io.Reader) (int, error)

func PickUrl

func PickUrl(urls []string, preferHttp bool) string

func PromptForInput

func PromptForInput(prompt string) string

PromptForInput prompts on stdin and reads a line. Empty string is returned on error

func ReadBigEndianInt32

func ReadBigEndianInt32(r io.Reader) (v int32, err error)

func ReadBigEndianInt64

func ReadBigEndianInt64(r io.Reader) (v int64, err error)

func ReadBigEndianUint32

func ReadBigEndianUint32(r io.Reader) (v uint32, err error)

func ReadBigEndianUint64

func ReadBigEndianUint64(r io.Reader) (v uint64, err error)

func ReadByte

func ReadByte(r io.Reader) (v byte, err error)

func ReadExactly

func ReadExactly(n int, r io.Reader) (data []byte, err error)

func Rewind

func Rewind(r io.ReadSeeker)

func RoundUp

func RoundUp(numToRound, multiple uint64) uint64

RoundUp rounds up. Amazing this does not exist in the standard packages

func SeparatedStringList

func SeparatedStringList(separator string, items ...interface{}) string

func SetLoggingLevel

func SetLoggingLevel(level LoggingLevel)

func SetLoggingLevelFromName

func SetLoggingLevelFromName(level string)

func StringKeysOf

func StringKeysOf(m map[string]bool) []string

func StringToBytes

func StringToBytes(s string) []byte

func StringToEthAddress

func StringToEthAddress(s string) (ea [20]byte)

func ToJsonString

func ToJsonString(data interface{}) string

func WriteLastLines

func WriteLastLines(w io.Writer, filepath string, numLines int)

WriteLastLines writes the last numLines from filepath to w

func WriteTempFile

func WriteTempFile(r io.Reader) string

WriteTempFile writes from the reader to a temp file and returns the path of the file or an empty string on error

func Yes

func Yes(prompt string) bool

Types

type LoggingLevel

type LoggingLevel int
const (
	LogLevelUnknown LoggingLevel = iota
	LogLevelTrace
	LogLevelDebug
	LogLevelInfo
	LogLevelWarning
	LogLevelError
)

func GetLoggingLevel

func GetLoggingLevel() LoggingLevel

Jump to

Keyboard shortcuts

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