utils

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CtxLogger added in v0.3.0

func CtxLogger(ctx context.Context) *slog.Logger

CtxLogger returns logger from context. If logger is not set, return default logger

func CtxRequestID added in v0.3.0

func CtxRequestID(ctx context.Context) (types.RequestID, context.Context)

CtxRequestID returns request ID from context. If request ID is not set, return new request ID and context with it

func CtxTime added in v0.3.0

func CtxTime(ctx context.Context) time.Time

CtxTime returns time from context. If time is not set, return current time and context with it

func CtxWithLogger added in v0.3.0

func CtxWithLogger(ctx context.Context, logger *slog.Logger) context.Context

WithLogger returns a new context with logger

func CtxWithTime added in v0.3.0

func CtxWithTime(ctx context.Context, timeFunc TimeFunc) context.Context

CtxWithTime returns a new context with time function

func DumpJson added in v0.3.0

func DumpJson(t *testing.T, path string, v interface{})

DumpJson dumps v into JSON file for test code. If it fails, it fails the test.

func HandleError added in v0.3.0

func HandleError(ctx context.Context, msg string, err error)

func HashBranch added in v0.3.0

func HashBranch(branch string) string

func LoadEnv added in v0.3.0

func LoadEnv(t *testing.T, name string) string

LoadEnv loads environment variable and return its value for test code. If the variable is not set, it skips the test.

func LoadJson added in v0.3.0

func LoadJson(t *testing.T, path string, v interface{})

LoadJson loads JSON file and decode it into v for test code. If it fails, it fails the test.

func Logger

func Logger() *slog.Logger

func ReconfigureLogger added in v0.2.0

func ReconfigureLogger(logFormat, logLevel, logOutput string) error

func SafeClose added in v0.2.0

func SafeClose(closer io.Closer)

func SafeRemove added in v0.2.0

func SafeRemove(path string)

func SafeRemoveAll added in v0.2.0

func SafeRemoveAll(path string)

func SafeRollback added in v0.2.0

func SafeRollback(tx *sql.Tx)

Types

type TimeFunc added in v0.3.0

type TimeFunc func() time.Time

Jump to

Keyboard shortcuts

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