btu

package module
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 13, 2025 License: BSD-3-Clause Imports: 8 Imported by: 9

README

btu

Some utilities functions for go programs. "btu" stands for "brothertoad utilities". I chose not to use the name utils, since there are probably already a few modules out there named utils. 😁

As a relative newcomer to the gopher world, I found myself adding a few common functions to each of my projects. I decided to put them in one module so I could reuse them. Note that my projects are usually command line applications, and simply log a message and exit if something goes wrong.

Documentation

Index

Constants

View Source
const DEBUG = 5
View Source
const ERROR = 2
View Source
const FATAL = 1
View Source
const INFO = 4
View Source
const TRACE = 6
View Source
const WARN = 3

Variables

This section is empty.

Functions

func Atoi added in v1.5.0

func Atoi(a string) int

func Atoi2 added in v1.5.0

func Atoi2(s string, msg string, a ...any) int

func CheckError

func CheckError(err error)

func CheckError2 added in v1.5.0

func CheckError2(err error, msg string, a ...any)

func CopyFile

func CopyFile(src, dst string)

Got this from https://stackoverflow.com/questions/21060945/simple-way-to-copy-a-file Copy the src file to dst. Any existing file will be overwritten and the file attributes will not be copied. Note that like all the other functions in this module, an error is fatal to the calling program.

func CreateDir

func CreateDir(dir string)

func CreateDirForFile added in v1.1.0

func CreateDirForFile(path string)

func CreateFile

func CreateFile(path string) *os.File

func Debug

func Debug(msg string, a ...any)

func DirExists

func DirExists(dir string) bool

func DirMustExist

func DirMustExist(dir string)

func Error

func Error(msg string, a ...any)

func Fatal

func Fatal(msg string, a ...any)

func FileExists

func FileExists(path string) bool

func GetNumberOrQuit added in v1.5.0

func GetNumberOrQuit(prompt string) int

func GetResponse added in v1.5.0

func GetResponse(prompt string) string

func Info

func Info(msg string, a ...any)

func IsDir added in v1.4.0

func IsDir(dir string) bool

Like the above, but doesn't fatal out if the path is a regular file.

func Log added in v1.4.0

func Log(level int, msg string, a ...any)

An exported version of logMsg.

func OpenFile added in v1.2.0

func OpenFile(path string) *os.File

func ParseFloat64 added in v1.5.0

func ParseFloat64(s string, msg string, a ...any) float64

func ParseInt64 added in v1.5.0

func ParseInt64(s string, msg string, a ...any) int64

func ReadFileB

func ReadFileB(path string) []byte

The B suffix means "byte".

func ReadFileL added in v1.5.0

func ReadFileL(path string) []string

The L suffix means "lines".

func ReadFileS

func ReadFileS(path string) string

The S suffix means "string".

func SetLogLevel

func SetLogLevel(level int)

func SetLogLevelByName added in v1.3.0

func SetLogLevelByName(name string)

func Trace added in v1.3.0

func Trace(msg string, a ...any)

func Warn

func Warn(msg string, a ...any)

Types

This section is empty.

Jump to

Keyboard shortcuts

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