Documentation ¶
Index ¶
- Constants
- Variables
- func DBQueryJSON(ctx context.Context, db hub.DB, query string, args ...interface{}) ([]byte, error)
- func DBQueryJSONWithPagination(ctx context.Context, db hub.DB, query string, args ...interface{}) (*hub.JSONQueryResult, error)
- func DBQueryUnmarshal(ctx context.Context, db hub.DB, v interface{}, query string, ...) error
- func DBTransact(ctx context.Context, db hub.DB, txFunc func(pgx.Tx) error) (err error)
- func ReadRegularFile(name string) ([]byte, error)
- func SetupConfig(cmd string) (*viper.Viper, error)
- func SetupDB(cfg *viper.Viper) (*pgxpool.Pool, error)
- func SetupHTTPClient(restricted bool, timeout time.Duration) hub.HTTPClient
- func SetupImageStore(cfg *viper.Viper, db pg.DB, hc img.HTTPClient) (img.Store, error)
- func SetupLogger(cfg *viper.Viper, fields map[string]interface{}) error
Constants ¶
const ( // DBLockKeyUpdatePackagesViews represents the lock key used when updating // the packages views counters in the database. DBLockKeyUpdatePackagesViews = 1 )
Variables ¶
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 )
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
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 ¶
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
ReadRegularFile is a wrapper around os.ReadFile that only operates on regular files.
func SetupConfig ¶
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 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 ¶
SetupImageStore creates a new image store based on the configuration provided.
Types ¶
This section is empty.