misc

package
v1.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EllipsisURL

func EllipsisURL(urlString string, truncateThreshold int) string

func ExtensionlessFileName

func ExtensionlessFileName(filePath string) string

func FirstElementOfPath

func FirstElementOfPath(path string) string

func IOCopyWithContext added in v1.3.3

func IOCopyWithContext(ctx context.Context, dst io.Writer, src io.Reader) (int64, error)

IOCopyWithContext performs a cancelable io.Copy

func IsNil

func IsNil(v interface{}) bool

IsNil returns true if v holds a nil reference, even if it is a typed nil interface value.

func JoinNonEmpty

func JoinNonEmpty(stringList []string, sep string) string

func LogPanic

func LogPanic()

LogPanic temporarily recovers from a panic (if there is one) and then logs it with Panicf() of Go's log library so that a writer attached with log.SetOutput() can deal with it (e.g. log it to a file), then lets the panic resume.

func LogRecoveredValue added in v1.3.2

func LogRecoveredValue(r interface{})

func MakePathAbsolute

func MakePathAbsolute(path string, absoluteReferencePath string) string

func MustGetRandomHexString

func MustGetRandomHexString(byteCount int) string

func MustJoinURL

func MustJoinURL(base, reference string) string

func MustParseURL

func MustParseURL(urlString string) *url.URL

func MustReadAll

func MustReadAll(fromReader io.Reader) []byte

func MustStripLastURLPathElement

func MustStripLastURLPathElement(urlString string) string

func MustUnmarshalJSON

func MustUnmarshalJSON(data []byte, v interface{})

func MustWaitForContext

func MustWaitForContext(ctx context.Context, timeout time.Duration)

func NewUserErrorFromErrors added in v1.5.0

func NewUserErrorFromErrors(errs ...error) error

NewUserErrorFromErrors returns the first non-nil error in the variadic parameter list if it is a *UserError. If the first non-nil error is not a *UserError, one is built using UserErrorf() with a generic message revealing the result of Error().

func RemoveLines

func RemoveLines(s string, from, to int) (string, error)

func RuneIndexToByteIndex

func RuneIndexToByteIndex(s string, runeIndex int) int

func ShortString

func ShortString(s string, leadingCount int, trailingCount int) string

func SplitTrailing added in v1.3.2

func SplitTrailing(s string, trailSet string) (lead, trail string)

func StripFirstPathElement

func StripFirstPathElement(filePath string, sep rune) (newPath, strippedElement string)

func StripTrailingLineBreak

func StripTrailingLineBreak(s string) string

func TryRemoveLines

func TryRemoveLines(s string, from, to int) string

func UserErrorf added in v1.5.0

func UserErrorf(cause error, userMessageFormat string, args ...interface{}) error

UserErrorf constructs a new *UserError with given cause and formatted message. The message should start with a capital letter and have proper punctuation - but no word-wrapping line-breaks - for display in a dialog.

func WaitCancelable added in v1.4.0

func WaitCancelable(ctx context.Context, c <-chan struct{})

func WaitForContext

func WaitForContext(ctx context.Context, timeout time.Duration) error

func WaitForSignal

func WaitForSignal(c <-chan struct{}, timeout time.Duration) bool

func WordWrap

func WordWrap(text string, lineWidth int) string

WordWrap performs word-wrapping on space-separated words within text, keeping existing newline characters intact. Any words which exceed lineWidth in length will move to a new line, but words themself will never be split.

func WordWrapIgnoreNewLine

func WordWrapIgnoreNewLine(text string, lineWidth int) string

WordWrapIgnoreNewLine performs word-wrapping on space-separated words within text, whereas any newline characters are treated as spaces themselves. Any words which exceed lineWidth in length will move to a new line, but words themself will never be split.

func WriteAttempter added in v1.4.0

func WriteAttempter(c chan<- struct{}) func()

Types

type UserError added in v1.5.0

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

UserError is an error with a cause-agnostic message and the added semantic of that message being suitable for display to users, i.e. non-programmers. It allows you to construct an error which will return a cause with Unwrap(), without the unwrapped error's message appearing in strings returned from Message().

func (*UserError) Error added in v1.5.0

func (e *UserError) Error() string

func (*UserError) Message added in v1.5.0

func (e *UserError) Message() string

Message returns a user-readable explanation of the error.

func (*UserError) Unwrap added in v1.5.0

func (e *UserError) Unwrap() error

Jump to

Keyboard shortcuts

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