gotils

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2023 License: MIT Imports: 6 Imported by: 2

README

codecov Go Report Card

Gotils

Golang utilities for building applications.

Why?

I found myself implementing almost the same utility functions in my new Go projects and it started to annoyed me.

I know there are a lot of other mature and good quality packages out there, but for me, who started using Go not long ago, it was a good exercise to implement these lightweight helpers.

Documentation

Index

Constants

View Source
const (
	LogLevelDebug = LogLevel(iota)
	LogLevelInfo
	LogLevelWarning
	LogLevelError
	LogLevelPanic
)
View Source
const ConfigLogLevel = EnvConfig("LOG_LEVEL")
View Source
const ErrorLogLevelNotSet = Error("LOG_LEVEL_NOT_SET")
View Source
const ErrorTimeout = Error("TIMEOUT_ERROR")

Variables

This section is empty.

Functions

func DateTimeFromString

func DateTimeFromString(dateTimeStr string) (*time.Time, error)

func DateTimeFromStringPanic

func DateTimeFromStringPanic(dateTimeStr string) *time.Time

Useful in tests

func NewGoroGroup

func NewGoroGroup() *goroGroup

func NewTimeout

func NewTimeout(duration time.Duration) *timeout

func NewTimeoutMs

func NewTimeoutMs(durationMs uint) *timeout

Useful in tests

func NilOrPanic

func NilOrPanic(err error)

Useful in tests

func Pointer

func Pointer[T any](value T) *T

func Reduce added in v0.1.2

func Reduce[T any](arr []T, f func(accumulator, currentValue T) T) T

func ResultOrPanic

func ResultOrPanic[T any](res T, err error) T

Useful in tests

Types

type EnvConfig

type EnvConfig string

func (EnvConfig) Load

func (val EnvConfig) Load() string

type Error

type Error string

func (Error) Error

func (e Error) Error() string

type LogLevel

type LogLevel uint8

func LogLevelFromEnv

func LogLevelFromEnv() (LogLevel, error)

type Logger

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

func NewLogger

func NewLogger(level LogLevel, out, err io.Writer) *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string, values ...any)

func (*Logger) Error

func (l *Logger) Error(msg string, values ...any)

func (*Logger) Info

func (l *Logger) Info(msg string, values ...any)

func (*Logger) Panic

func (l *Logger) Panic(msg string, values ...any)

func (*Logger) Warning

func (l *Logger) Warning(msg string, values ...any)

Jump to

Keyboard shortcuts

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