formatter

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package formatter implements formatters and helper types for err2. See more information from err2.SetFormatter.

Index

Constants

This section is empty.

Variables

Decamel is pre-implemented and default formatter to produce human readable error strings from function names.

func CopyFile(..)  -> "copy file: file not exists"
                       ^-------^ -> generated from 'func CopyFile'
View Source
var DecamelAndRmTryPrefix = &Formatter{DoFmt: str.DecamelRmTryPrefix}

DecamelAndRmTryPrefix is pre-implemented formatter to produce human readable error strings from function names. It's similar to Decamel but also removes try-prefixes from function names:

func TryCopyFile(..)  -> "copy file: file not exists"
                          ^-------^ -> generated from 'func TryCopyFile'

It's convenient helper for those who wants to write compact functions by following convention to always add 'Try' prefix to those functions that can throw errors thru panics. Fox example, if you're using helpers like github.com/lainio/err2/assert.That and github.com/lainio/err2/try.To but you don't want to handle errors in your current function, it's still good practice to use convention to mark that function to throw errors. However, we suggest that you don't do that in your packages public API functions.

View Source
var Noop = &Formatter{DoFmt: func(i string) string { return i }}

Noop is preimplemented formatter that does nothing to function name.

func CopyFile(..)  -> "CopyFile: file not exists"
                       ^------^ -> function name as it is: CopyFile

Functions

This section is empty.

Types

type DoFmt

type DoFmt func(i string) string

DoFmt is a helper function type which allows reuse Formatter struct for the implementations.

type Formatter

type Formatter struct {
	DoFmt
}

Formatter is a helper struct which wraps the actual formatting function which is called during the function name processing to produce errors automatically.

func (*Formatter) Format

func (f *Formatter) Format(input string) string

Format just calls function set in the DoFmt field.

type Interface

type Interface interface {
	Format(input string) string
}

Interface is a formatter interface. The implementers are used for automatic error message generation from function names. See more information from err2.Handle.

Jump to

Keyboard shortcuts

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