misc

package module
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 4 Imported by: 0

README

Short snippets of functions that are used in different go programs but are too small to justify a modules of its own.

Current files:

File Description
formats Some ANSI color settings and other format functions
errors A few functions to handle errors
sliceops Functions to add or remove from slices

Documentation

Overview

Package misc provides short helpers for ANSI colouring and numeric formatting

Package misc are just short snippets of functions

Index

Constants

View Source
const (
	ErrPanic = iota
	MsgPanic
	ErrMsgPanic
	ErrFatal
	MsgFatal
	ErrMsgFatal
	ErrPrint
	MsgPrint
	ErrMsgPrint
)
View Source
const (
	Green     = "\033[92m%s\033[0m"
	Red       = "\033[91m%s\033[0m"
	Purple    = "\033[95m%s\033[0m"
	Yellow    = "\033[96m%s\033[0m"
	LightBlue = "\033[94m%s\033[0m"
)

Colour helpers

View Source
const Bold = "\033[1m%s\033[0m"

ANSI colour codes Bold text

View Source
const BoldRightSize = "\033[1m%*s\033[0m"

BoldRightSize formats a string right-aligned in a field of width w

View Source
const BoldSize = "\033[1m%-*s\033[0m"

BoldSize formats a string left-aligned in a field of width w

Variables

This section is empty.

Functions

func AddToSlice

func AddToSlice(sl []string, str string) []string

AddToSlice adds a string to a slice if it doesn't already exists.

func Boldf

func Boldf(format string, args ...interface{}) string

Short wrappers that hide the underlying fmt call

func FormatFloat

func FormatFloat(num float64, prc int, trim bool) string

FormatFloat renders a float64 with a fixed precision If trim is true, trailing zeroes and a dangling decimal point are removed

Example:

FormatFloat(1.2300, 4, true) // "1.23" FormatFloat(1.2, 4, false) // "1.2000"

func Greenf

func Greenf(format string, args ...interface{}) string

func LightBluef

func LightBluef(format string, args ...interface{}) string

func Purplef

func Purplef(format string, args ...interface{}) string

func Redf

func Redf(format string, args ...interface{}) string

func RemoveFromSlice

func RemoveFromSlice(sl []string, str string) []string

RemoveFromSlice removes a string from a slice if it exists.

func ShowError

func ShowError(e error, msg string, errType ErrorType)

ShowError Displays errors depending on the type of error Error types: ErrPanic - display error and panic MsgPanic - display message and panic ErrMsgPanic - display error and message and panic ErrFatal - display error and exit MsgFatal - display message and exit ErrMsgFatal - display error and message and exit ErrPrint - display error MsgPrint - display message ErrMsgPrint - display error and message

func Yellowf

func Yellowf(format string, args ...interface{}) string

Types

type ErrorType

type ErrorType int

Jump to

Keyboard shortcuts

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