common

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoRetry

func AutoRetry[T any](
	ctx context.Context,
	supplier func() (T, error),
	maxRetryTimes int,
	retryInterval time.Duration,
	logger *logging.Logger) (T, error)

AutoRetry retries the supplier automatically, with given time limit and interval. If maximum retry time limit is reached and the supplier still fails, the last error will be returned. If logger is not nil, retry information will be printed to it.

func CombineFileName added in v0.2.0

func CombineFileName(base string, ext string) string

func CopyToFileWithBuffer

func CopyToFileWithBuffer(
	ctx context.Context,
	out *os.File,
	in io.Reader,
	buffer []byte,
	chunkSize int,
	syncFile bool,
) (written int64, err error)

CopyToFileWithBuffer copies data from io.Reader to os.File with given buffer and read chunk size. The reader and file won't be closed. If syncFile is set, the file will be synced after every read.

func GetFileExtensionFromUrl

func GetFileExtensionFromUrl(rawUrl string) (string, error)

GetFileExtensionFromUrl copied from https://elisegev.medium.com/get-a-file-extension-from-a-url-in-golang-5061d4a298a

func IsErrorOfType

func IsErrorOfType(err, target error) bool

IsErrorOfType is a modified version of errors.Is, which loosen the check condition

func Max

func Max[T Number](t1 T, t2 T) T

func Min

func Min[T Number](t1 T, t2 T) T

func PrettyBytes

func PrettyBytes(b uint64) string

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Opt

type Opt[T any] interface {
	OrElse(thing T) T
}

func Errorable

func Errorable[T any](thing T, err error) Opt[T]

func Nullable

func Nullable[T any](ptr *T) Opt[T]

func Zeroable

func Zeroable[T any](thing T) Opt[T]

type OptError

type OptError[T any] struct {
	// contains filtered or unexported fields
}

func (OptError[T]) OrElse

func (o OptError[T]) OrElse(thing T) T

type OptNull

type OptNull[T any] struct {
	// contains filtered or unexported fields
}

func (OptNull[T]) OrElse

func (o OptNull[T]) OrElse(thing T) T

type OptZero

type OptZero[T any] struct {
	// contains filtered or unexported fields
}

func (OptZero[T]) OrElse

func (o OptZero[T]) OrElse(thing T) T

type RoomId

type RoomId uint64

Jump to

Keyboard shortcuts

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