utils

package
v0.0.0-...-b9c5443 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package utils contains various small utility functions

Index

Constants

This section is empty.

Variables

View Source
var AnyContext = mock.MatchedBy(func(c context.Context) bool {

	return true
})

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 Filter

func Filter[T any](slice []T, test func(T) bool) []T

func GetCaller

func GetCaller(skip int) (string, error)

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

func GetLogLevelFromEnv() (zerolog.Level, error)

GetLogLevelFromEnv gets the logging level from the environment variable LOG_LEVEL

func GetenvBool

func GetenvBool(key string) (bool, error)

GetenvBool returns an environment variable as boolean

func InitLogging

func InitLogging()

InitLogging configure log library to output to console with appropriate levels

func Intersection

func Intersection(a, b []string) []string

Intersection returns a new slice containing items in common from a and b

func IsEqual

func IsEqual(a, b []string) bool

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

func Unique

func Unique[T comparable](arr []T) []T

Unique returns a slice without duplicates.

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 NewMockConn() (*MockConn, error)

func (*MockConn) WaitForNotification

func (m *MockConn) WaitForNotification(ctx context.Context) (*pgconn.Notification, error)

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

Jump to

Keyboard shortcuts

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