asciichgolangpublic

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

README

asciichgolangpublic

This module helps to write infrastructure and/or automation related microservices and CLIs easier and faster. By providing a lot of convenience functions, sanity checks during runtime and detailed error messages it can be used to write easy to understand software to automate repeatable work. The focus is on ease of use and developer speed instead of algorithm speed and computer resource efficiency.

Logging

To provide easy readable CLI output its recommended to use the provided logging functions:

package main

import "github.com/asciich/asciichgolangpublic"

func main() {
	asciichgolangpublic.LogInfo("Shown without additional color.")
	asciichgolangpublic.LogInfof("Shown without additional color. %s", "Also available with formatting.")

	asciichgolangpublic.LogGood("Good messages are green.")
	asciichgolangpublic.LogGoodf("Good messages are green. %s", "Also available with formatting.")

	asciichgolangpublic.LogChanged("Changes are purple.")
	asciichgolangpublic.LogChangedf("Changes are purple. %s", "Also available with formatting.")

	asciichgolangpublic.LogWarn("Warnings are yellow.")
	asciichgolangpublic.LogWarnf("Warnings are yellow. %s", "Also available with formatting.")

	asciichgolangpublic.LogError("Errors are red.")
	asciichgolangpublic.LogErrorf("Errors are red. %s", "Also available with formatting.")

	asciichgolangpublic.LogFatalf("Fatal will exit with a red error message and exit code %d", 1)
}

Output produced by this example code:

Errors

It's recommended to use TracedError whenever an error occurs with a custom error message. Error wrapping by directly passing errors or using the %w format string in TracedErrorf is supported. TracedErrors give you a nice debug output including the stack trace in a human readable form compatiple to VSCode (affected sources can directly be opened from Terminal).

Example usage:

func inThisFunctionSomethingGoesWrong() (err error) {
    return asciichgolangpublic.TracedError("This is an error message") // Use TracedErrors when an error occures.
}

err = inThisFunctionSomethingGoesWrong()
asciichgolangpublic.Errors().IsTracedError(err) // returns true for all TracedErrors.
asciichgolangpublic.Errors().IsTracedError(fmt.Errorf("another error")) // returns false for all non TracedErrors.

err.Error() // includes the error message and the stack trace as human readable text.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTracedError = errors.New("asciichgolangpublic TracedError base")
View Source
var ErrTracedErrorEmptyString = errors.New("asciichgolangpublic TracedError empty string")
View Source
var ErrTracedErrorNil = errors.New("asciichgolangpublic TracedError nil")
View Source
var ErrTracedErrorNotImplemented = errors.New("asciichgolangpublic TracedError not implemented")

Functions

func Log

func Log(logmessage string)

func LogBold

func LogBold(logmessage string)

func LogChanged

func LogChanged(logmessage string)

func LogChangedf

func LogChangedf(logmessage string, args ...interface{})

func LogError

func LogError(logmessage string)

func LogErrorf

func LogErrorf(logmessage string, args ...interface{})

func LogFatal

func LogFatal(logmessage string)

func LogFatalWithTrace

func LogFatalWithTrace(errorMessageOrError interface{})

func LogFatalWithTracef

func LogFatalWithTracef(logmessage string, args ...interface{})

func LogFatalf

func LogFatalf(logmessage string, args ...interface{})

func LogGoError

func LogGoError(err error)

func LogGoErrorFatal

func LogGoErrorFatal(err error)

func LogGoErrorFatalWithTrace

func LogGoErrorFatalWithTrace(err error)

func LogGood

func LogGood(logmessage string)

func LogGoodf

func LogGoodf(logmessage string, args ...interface{})

func LogInfo

func LogInfo(logmessage string)

func LogInfof

func LogInfof(logmessage string, args ...interface{})

func LogWarn

func LogWarn(logmessage string)

func LogWarnf

func LogWarnf(logmessage string, args ...interface{})

func MustFormatAsTestname

func MustFormatAsTestname(objectToFormat interface{}) (testname string)

func TracedError

func TracedError(errorMessageOrError interface{}) (tracedError error)

Create a new error with given error or error message. TracedErrors extends the error message by a human readable stack trace.

func TracedErrorEmptyString

func TracedErrorEmptyString(stringVarName string, errorToUnwrap ...error) (tracedError error)

func TracedErrorNil

func TracedErrorNil(nilVarName string) (tracedError error)

func TracedErrorNilf

func TracedErrorNilf(formatString string, args ...interface{}) (tracedError error)

func TracedErrorNotImplemented

func TracedErrorNotImplemented() (tracedError error)

func TracedErrorf

func TracedErrorf(formatString string, args ...interface{}) (tracedError error)

Create a new error with given error or error message. TracedErrors extends the error message by a human readable stack trace. Error wrapping using '%w' in format string is supported.

Types

type Directory

type Directory interface {
	GetLocalPath() (localPath string, err error)
	MustGetLocalPath() (localPath string)
}

type ErrorsService

type ErrorsService struct{}

func Errors

func Errors() (e *ErrorsService)

func NewErrorsService

func NewErrorsService() (e *ErrorsService)

func (ErrorsService) IsEmptyStringError

func (e ErrorsService) IsEmptyStringError(err error) (isEmptyStringError bool)

func (ErrorsService) IsNilError

func (e ErrorsService) IsNilError(err error) (IsNilError bool)

func (ErrorsService) IsNotImplementedError

func (e ErrorsService) IsNotImplementedError(err error) (isNotImplementedError bool)

func (ErrorsService) IsTracedError

func (e ErrorsService) IsTracedError(err error) (isTracedError bool)

Returns true if given error 'err' is a TracedError, false otherwise.

type File

type File interface {
	Exists() (exists bool, err error)
	GetLocalPath() (localPath string, err error)
	GetUriAsString() (uri string, err error)
	MustGetLocalPath() (localPath string)
	MustGetUriAsString() (uri string)
}

A File represents any kind of file regardless if a local file or a remote file.

type LocalFile

type LocalFile struct {
	// contains filtered or unexported fields
}

A LocalFile represents a locally available file.

func MustNewLocalFileByPath

func MustNewLocalFileByPath(localPath string) (l *LocalFile)

func NewLocalFile

func NewLocalFile() (l *LocalFile)

func NewLocalFileByPath

func NewLocalFileByPath(localPath string) (l *LocalFile, err error)

func (LocalFile) Exists

func (l LocalFile) Exists() (exists bool, err error)

func (*LocalFile) GetLocalPath

func (l *LocalFile) GetLocalPath() (path string, err error)

func (*LocalFile) GetPath

func (l *LocalFile) GetPath() (path string, err error)

func (*LocalFile) GetUriAsString

func (l *LocalFile) GetUriAsString() (uri string, err error)

func (LocalFile) IsPathSet

func (l LocalFile) IsPathSet() (isSet bool)

func (*LocalFile) MustExists

func (l *LocalFile) MustExists() (exists bool)

func (*LocalFile) MustGetLocalPath

func (l *LocalFile) MustGetLocalPath() (path string)

func (*LocalFile) MustGetPath

func (l *LocalFile) MustGetPath() (path string)

func (*LocalFile) MustGetUriAsString

func (l *LocalFile) MustGetUriAsString() (uri string)

func (*LocalFile) MustSetPath

func (l *LocalFile) MustSetPath(path string)

func (*LocalFile) SetPath

func (l *LocalFile) SetPath(path string) (err error)

type PathsService

type PathsService struct{}

func NewPathsService

func NewPathsService() (p *PathsService)

func Paths

func Paths() (p *PathsService)

func (*PathsService) IsAbsolutePath

func (p *PathsService) IsAbsolutePath(path string) (isRelative bool)

Returns true if path is an absolute path. An empty string as path will always be false.

func (*PathsService) IsRelativePath

func (p *PathsService) IsRelativePath(path string) (isRelative bool)

Returns true if path is a relative path. An empty string as path will always be false.

type PointersService

type PointersService struct{}

func NewPointersService

func NewPointersService() (p *PointersService)

func Pointers

func Pointers() (pointers *PointersService)

func (*PointersService) IsPointer

func (p *PointersService) IsPointer(objectToTest interface{}) (isPointer bool)

type StructsService

type StructsService struct{}

func NewStructsService

func NewStructsService() (s *StructsService)

func Structs

func Structs() (structs *StructsService)

func (*StructsService) GetFieldValuesAsString

func (s *StructsService) GetFieldValuesAsString(structToGetFieldsFrom interface{}) (values []string, err error)

func (*StructsService) IsPointerToStruct

func (s *StructsService) IsPointerToStruct(objectToTest interface{}) (isStruct bool)

func (*StructsService) IsStruct

func (s *StructsService) IsStruct(objectToTest interface{}) (isStruct bool)

func (*StructsService) IsStructOrPointerToStruct

func (s *StructsService) IsStructOrPointerToStruct(objectToTest interface{}) (isStruct bool)

func (*StructsService) MustGetFieldValuesAsString

func (s *StructsService) MustGetFieldValuesAsString(structToGetFieldsFrom interface{}) (values []string)

type TerminalColorsService

type TerminalColorsService struct{}

func NewTerminalColorsService

func NewTerminalColorsService() (t *TerminalColorsService)

func TerminalColors

func TerminalColors() (terminalColors *TerminalColorsService)

func (*TerminalColorsService) GetCodeBlack

func (t *TerminalColorsService) GetCodeBlack() (code string)

func (*TerminalColorsService) GetCodeBlue

func (t *TerminalColorsService) GetCodeBlue() (code string)

func (*TerminalColorsService) GetCodeBrightBlack

func (t *TerminalColorsService) GetCodeBrightBlack() (code string)

func (*TerminalColorsService) GetCodeBrightBlue

func (t *TerminalColorsService) GetCodeBrightBlue() (code string)

func (*TerminalColorsService) GetCodeBrightCyan

func (t *TerminalColorsService) GetCodeBrightCyan() (code string)

func (*TerminalColorsService) GetCodeBrightGreen

func (t *TerminalColorsService) GetCodeBrightGreen() (code string)

func (*TerminalColorsService) GetCodeBrightMagenta

func (t *TerminalColorsService) GetCodeBrightMagenta() (code string)

func (*TerminalColorsService) GetCodeBrightRed

func (t *TerminalColorsService) GetCodeBrightRed() (code string)

func (*TerminalColorsService) GetCodeBrightWhite

func (t *TerminalColorsService) GetCodeBrightWhite() (code string)

func (*TerminalColorsService) GetCodeBrightYellow

func (t *TerminalColorsService) GetCodeBrightYellow() (code string)

func (*TerminalColorsService) GetCodeCyan

func (t *TerminalColorsService) GetCodeCyan() (code string)

func (*TerminalColorsService) GetCodeGray

func (t *TerminalColorsService) GetCodeGray() (code string)

func (*TerminalColorsService) GetCodeGreen

func (t *TerminalColorsService) GetCodeGreen() (code string)

func (*TerminalColorsService) GetCodeMangenta

func (t *TerminalColorsService) GetCodeMangenta() (code string)

func (*TerminalColorsService) GetCodeNoColor

func (t *TerminalColorsService) GetCodeNoColor() (code string)

func (*TerminalColorsService) GetCodeRed

func (t *TerminalColorsService) GetCodeRed() (code string)

func (*TerminalColorsService) GetCodeWhite

func (t *TerminalColorsService) GetCodeWhite() (code string)

func (*TerminalColorsService) GetCodeYellow

func (t *TerminalColorsService) GetCodeYellow() (code string)

type TestsService

type TestsService struct{}

func NewTestsService

func NewTestsService() (t *TestsService)

func Tests

func Tests() (tests *TestsService)

func (*TestsService) FormatAsTestname

func (t *TestsService) FormatAsTestname(objectToFormat interface{}) (testname string, err error)

func (*TestsService) MustFormatAsTestname

func (t *TestsService) MustFormatAsTestname(objectToFormat interface{}) (testname string)

type TracedErrorType

type TracedErrorType struct {
	// contains filtered or unexported fields
}

func NewTracedErrorType

func NewTracedErrorType() (t *TracedErrorType)

func (TracedErrorType) Error

func (t TracedErrorType) Error() (errorMessage string)

func (*TracedErrorType) GetErrorsToUnwrap

func (t *TracedErrorType) GetErrorsToUnwrap() (errorsToUnwrap []error, err error)

func (*TracedErrorType) GetFormattedError

func (t *TracedErrorType) GetFormattedError() (formattedError error, err error)

func (*TracedErrorType) GetFunctionCalls

func (t *TracedErrorType) GetFunctionCalls() (functionCalls []string, err error)

func (*TracedErrorType) MustGetErrorsToUnwrap

func (t *TracedErrorType) MustGetErrorsToUnwrap() (errorsToUnwrap []error)

func (*TracedErrorType) MustGetFormattedError

func (t *TracedErrorType) MustGetFormattedError() (formattedError error)

func (*TracedErrorType) MustGetFunctionCalls

func (t *TracedErrorType) MustGetFunctionCalls() (functionCalls []string)

func (*TracedErrorType) MustSetErrorsToUnwrap

func (t *TracedErrorType) MustSetErrorsToUnwrap(errorsToUnwrap []error)

func (*TracedErrorType) MustSetFormattedError

func (t *TracedErrorType) MustSetFormattedError(formattedError error)

func (*TracedErrorType) MustSetFunctionCalls

func (t *TracedErrorType) MustSetFunctionCalls(functionCalls []string)

func (*TracedErrorType) SetErrorsToUnwrap

func (t *TracedErrorType) SetErrorsToUnwrap(errorsToUnwrap []error) (err error)

func (*TracedErrorType) SetFormattedError

func (t *TracedErrorType) SetFormattedError(formattedError error) (err error)

func (*TracedErrorType) SetFunctionCalls

func (t *TracedErrorType) SetFunctionCalls(functionCalls []string) (err error)

func (TracedErrorType) Unwrap

func (t TracedErrorType) Unwrap() (errors []error)

Jump to

Keyboard shortcuts

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