utils

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsDir

func IsDir(name string) bool

IsDir determine whether the name exists and must be a dir.

func IsFile

func IsFile(name string) bool

IsFile determine whether the name exists and must be a file.

func MapSlice

func MapSlice[S any, T any](src []S, mapper func(S) T) []T

func MustReadOption

func MustReadOption[T string | int | *zap.SugaredLogger](options map[string]interface{}, key string) T

MustReadOption read a value from options map. Panic if key does not exist or the type of value is not T.

func MustReadStringOption

func MustReadStringOption(options map[string]interface{}, key string) string

MustReadStringOption read a string value from options map. Panic if key does not exist or the value is not a string type.

Types

type ErrorCollection

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

ErrorCollection is an error that packed a series of errors. Unlike fmt.Errorf, all the errors here are at the same level. The length of errors must > 0.

A typical use case is a function that performs operations on a lot of data, which are independent of each other and do not want to be interrupted by just an error.

func NewErrorCollection

func NewErrorCollection(errs []error) *ErrorCollection

NewErrorCollection create an ErrorCollection based on given errors. If the given errors is nil or empty, then return nil.

func (*ErrorCollection) Error

func (e *ErrorCollection) Error() string

Jump to

Keyboard shortcuts

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