storage

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultDBPingBackoff    = 2 * time.Second
	DefaultDBPingMaxRetries = 10
)

constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitHubStorer

type GitHubStorer interface {
	GitHubStore(payload *GitHubWebhookData) error
}

GitHubStorer defines storage behaviours for github webhook.

type GitHubWebhookData

type GitHubWebhookData struct {
	Payload    any
	Event      github.Event
	Target     string
	UserLogin  string
	DeliveryID uuid.UUID
	TargetID   uint64
	HookID     uint64
	UserID     int64
	Offset     int64
	Partition  int32
}

GitHubWebhookData presents `github` table fields.

type Manager

type Manager struct {
	Logger     *slog.Logger
	Pool       *pgxpool.Pool
	DSN        string
	BackOff    time.Duration
	MaxRetries uint8
}

Manager represents database manager.

func New

func New(options ...Option) (*Manager, error)

New instantiates new pgx connection pool.

func (Manager) GitHubStore

func (m Manager) GitHubStore(data *GitHubWebhookData) error

GitHubStore stores given github webhook data with extras to database.

func (Manager) Ping

func (m Manager) Ping() error

Ping implements a retry and backoff mechanism to check whether a database connection can be established.

type Option

type Option func(*Manager) error

Option represents option function type.

func WithBackoff

func WithBackoff(d time.Duration) Option

WithBackoff sets backoff duration.

func WithDSN

func WithDSN(s string) Option

WithDSN sets connection dsn.

func WithLogger

func WithLogger(l *slog.Logger) Option

WithLogger sets logger.

func WithMaxRetries

func WithMaxRetries(i int) Option

WithMaxRetries sets max retries value.

type Storer

type Storer interface {
	Ping() error
	GitHubStorer
}

Storer defines storage behaviours for different webhooks.

Jump to

Keyboard shortcuts

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