util

package
v1.18.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DBLockKeyUpdatePackagesViews represents the lock key used when updating
	// the packages views counters in the database.
	DBLockKeyUpdatePackagesViews = 1
)

Variables

View Source
var (
	// ErrRestrictedConnection error indicates that connections to the provided
	// address are restricted.
	ErrRestrictedConnection = errors.New("restricted connection")

	// HTTPClientDefaultTimeout represents the default timeout used for http
	// clients.
	HTTPClientDefaultTimeout = 10 * time.Second
)
View Source
var (
	// ErrDBInsufficientPrivilege indicates that the user does not have the
	// required privilege to perform the operation.
	ErrDBInsufficientPrivilege = errors.New("ERROR: insufficient_privilege (SQLSTATE 42501)")
)

Functions

func DBQueryJSON added in v0.7.0

func DBQueryJSON(ctx context.Context, db hub.DB, query string, args ...interface{}) ([]byte, error)

DBQueryJSON is a helper that executes the query provided and returns a bytes slice containing the json data returned from the database.

func DBQueryJSONWithPagination added in v1.0.0

func DBQueryJSONWithPagination(
	ctx context.Context,
	db hub.DB,
	query string,
	args ...interface{},
) (*hub.JSONQueryResult, error)

DBQueryJSONWithPagination is a helper that executes the query provided and returns a JSONQueryResult instance containing the json data returned from the database.

func DBQueryUnmarshal added in v0.7.0

func DBQueryUnmarshal(ctx context.Context, db hub.DB, v interface{}, query string, args ...interface{}) error

DBQueryUnmarshal is a helper that executes the query provided and unmarshals the json data returned from the database into the value (v) provided.

func DBTransact

func DBTransact(ctx context.Context, db hub.DB, txFunc func(pgx.Tx) error) (err error)

DBTransact is a helper function that wraps some database transactions taking care of committing and rolling back when needed.

func ReadRegularFile added in v1.16.0

func ReadRegularFile(name string) ([]byte, error)

ReadRegularFile is a wrapper around os.ReadFile that only operates on regular files.

func SetupConfig

func SetupConfig(cmd string) (*viper.Viper, error)

SetupConfig creates a new Viper instance to handle the configuration for a particular cmd. Configuration can be provided in a config file or using env variables. See configs folder for some examples.

func SetupDB

func SetupDB(cfg *viper.Viper) (*pgxpool.Pool, error)

SetupDB creates a database connection pool using the configuration provided.

func SetupHTTPClient added in v0.19.0

func SetupHTTPClient(restricted bool, timeout time.Duration) hub.HTTPClient

SetupHTTPClient is a helper that returns an http client. If restricted is set to true, the http client won't be able to make requests to a set of restricted addresses.

func SetupImageStore

func SetupImageStore(
	cfg *viper.Viper,
	db pg.DB,
	hc img.HTTPClient,
) (img.Store, error)

SetupImageStore creates a new image store based on the configuration provided.

func SetupLogger

func SetupLogger(cfg *viper.Viper, fields map[string]interface{}) error

SetupLogger configures the global logger using the configuration provided.

Types

This section is empty.

Jump to

Keyboard shortcuts

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