Documentation ¶
Overview ¶
Package utils contains various small utility functions
Index ¶
- Variables
- func Combine[T comparable](list1 []T, list2 []T) []T
- func Difference[T comparable](list1 []T, list2 []T) []T
- func Filter[T any](slice []T, test func(T) bool) []T
- func GetCaller(skip int) (string, error)
- func GetLogLevelFromEnv() (zerolog.Level, error)
- func GetenvBool(key string) (bool, error)
- func InitLogging()
- func Intersection(a, b []string) []string
- func IsEqual(a, b []string) bool
- func SliceContains[T comparable](haystack []T, needle T) bool
- func Unique[T comparable](arr []T) []T
- type MockConn
- type Tx
Constants ¶
This section is empty.
Variables ¶
AnyContext will match any context.Context: empty ones as well as WithValue ones.
Functions ¶
func Combine ¶
func Combine[T comparable](list1 []T, list2 []T) []T
Combine combines two lists of string in a single one without duplicates.
func Difference ¶
func Difference[T comparable](list1 []T, list2 []T) []T
Difference returns the content of list 1 not present in list 2. list1 - list1 U list2
func GetCaller ¶
GetCaller returns the name of the function calling it. The argument skip is the number of stack frames to ascend, with 0 identifying the caller of GetCaller
func GetLogLevelFromEnv ¶
GetLogLevelFromEnv gets the logging level from the environment variable LOG_LEVEL
func GetenvBool ¶
GetenvBool returns an environment variable as boolean
func InitLogging ¶
func InitLogging()
InitLogging configure log library to output to console with appropriate levels
func Intersection ¶
Intersection returns a new slice containing items in common from a and b
func IsEqual ¶
IsEqual compares two slices and returns true if they both contains the same set of items.
func SliceContains ¶
func SliceContains[T comparable](haystack []T, needle T) bool
SliceContains will check if needle is found in haystack
Types ¶
type MockConn ¶
type MockConn struct { pgxmock.PgxConnIface mock.Mock }
MockConn augments pgxmock.PgxConnIface with a WaitForNotification method so that it implements dbal.Conn interface.
func NewMockConn ¶
func (*MockConn) WaitForNotification ¶
type Tx ¶
type Tx interface { Begin(ctx context.Context) (pgx.Tx, error) BeginFunc(ctx context.Context, f func(pgx.Tx) error) (err error) Commit(ctx context.Context) error Rollback(ctx context.Context) error CopyFrom(ctx context.Context, tableName pgx.Identifier, columnNames []string, rowSrc pgx.CopyFromSource) (int64, error) SendBatch(ctx context.Context, b *pgx.Batch) pgx.BatchResults LargeObjects() pgx.LargeObjects Prepare(ctx context.Context, name, sql string) (*pgconn.StatementDescription, error) Exec(ctx context.Context, sql string, arguments ...interface{}) (commandTag pgconn.CommandTag, err error) Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error) QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row QueryFunc(ctx context.Context, sql string, args []interface{}, scans []interface{}, f func(pgx.QueryFuncRow) error) (pgconn.CommandTag, error) Conn() *pgx.Conn }
Tx will generate a mock for pgx.Tx