adapters

package module
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2025 License: MIT Imports: 33 Imported by: 0

README

Go Adapters

Contains helpful adapters for various systems and technologies

Documentation

Index

Constants

View Source
const (
	S3ObjectNotExists int = iota
	S3ObjectExists
)
View Source
const (
	SelectKeyword string = "select"
	InsertKeyword string = "insert"
	DeleteKeyword string = "delete"
)
View Source
const (
	TmuxSessionExists int = iota
	TmuxSessionNotExists
)
View Source
const (
	TmuxEnterCmd        string = "C-m"
	TmuxHasSessionCmd   string = "has-session"
	TmuxNewSessionCmd   string = "new-session"
	TmuxNewWindowCmd    string = "new-window"
	TmuxSelectWindowCmd string = "select-window"
	TmuxAttachCmd       string = "attach-session"
	TmuxSendKeysCmd     string = "send-keys"
)
View Source
const Alias string = "tmux"
View Source
const ExDeleteQuery string = `
    DELETE FROM table
    WHERE id = @id
`
View Source
const ExInsertQuery string = `
    INSERT INTO table (
        data
    ) VALUES (
        @data
    ) RETURNING id
`
View Source
const ExRowExistsQuery string = `
    SELECT id
    FROM table
    WHERE id = @id
`
View Source
const ExSelectQuery string = `
    SELECT *
    FROM table
    WHERE id = @id
`
View Source
const (
	MaxDeleteKeys int = 1000
)
View Source
const (
	MaxPollFetches int = 1000
)

Variables

This section is empty.

Functions

func NewPgxPool added in v0.0.3

func NewPgxPool(ctx context.Context, connUrl string) (*pgxpool.Pool, error)

NewPgxPool creates a pgxpool.Pool

Types

type AWSAdapter

type AWSAdapter struct {
	// contains filtered or unexported fields
}

func NewAWSAdapter

func NewAWSAdapter(logger *slog.Logger, tracer trace.Tracer, opts ...AWSOpt) *AWSAdapter

func (*AWSAdapter) DeleteObjects

func (a *AWSAdapter) DeleteObjects(ctx context.Context, bucket string, objects []string, waiter interface{}) error

func (*AWSAdapter) GetObject

func (a *AWSAdapter) GetObject(ctx context.Context, bucket string, key string) (io.Reader, error)

func (*AWSAdapter) GetSecret added in v0.0.7

func (a *AWSAdapter) GetSecret(ctx context.Context, arn string, name string) (string, error)

func (*AWSAdapter) ListObjects

func (a *AWSAdapter) ListObjects(ctx context.Context, bucket string, prefix string, pager interface{}) ([]string, error)

func (*AWSAdapter) ObjectExists

func (a *AWSAdapter) ObjectExists(ctx context.Context, bucket string, key string) (int, error)

func (*AWSAdapter) PutObject

func (a *AWSAdapter) PutObject(ctx context.Context, data io.Reader, bucket string, key string) error

type AWSOpt

type AWSOpt func(a *AWSAdapter)

func WithAWSSpanAttrs added in v0.0.7

func WithAWSSpanAttrs(attrs ...attribute.KeyValue) AWSOpt

func WithS3Client

func WithS3Client(client S3Client) AWSOpt

func WithSecretsManagerClient added in v0.0.7

func WithSecretsManagerClient(client SecretsManagerClient) AWSOpt

type CmdAdapter added in v0.0.3

type CmdAdapter struct{}

func NewCmdAdapter added in v0.0.3

func NewCmdAdapter() *CmdAdapter

func (*CmdAdapter) Exec added in v0.0.3

func (a *CmdAdapter) Exec(ctx context.Context, cmd *exec.Cmd) (io.Reader, error)

type Command added in v0.0.3

type Command interface {
	Exec(context.Context, *exec.Cmd) (io.Reader, error)
}

type ErrAttachSession added in v0.0.3

type ErrAttachSession struct {
	// contains filtered or unexported fields
}

func (*ErrAttachSession) Error added in v0.0.3

func (e *ErrAttachSession) Error() string

type ErrAuthCode

type ErrAuthCode struct {
	// contains filtered or unexported fields
}

func (*ErrAuthCode) Error

func (e *ErrAuthCode) Error() string

type ErrCollectRows added in v0.0.3

type ErrCollectRows struct {
	// contains filtered or unexported fields
}

func (*ErrCollectRows) Error added in v0.0.3

func (e *ErrCollectRows) Error() string

type ErrConnect added in v0.0.3

type ErrConnect struct {
	// contains filtered or unexported fields
}

func (*ErrConnect) Error added in v0.0.3

func (e *ErrConnect) Error() string

type ErrCreateTopic added in v0.0.2

type ErrCreateTopic struct {
	// contains filtered or unexported fields
}

func (*ErrCreateTopic) Error added in v0.0.2

func (e *ErrCreateTopic) Error() string

type ErrDeleteObjects

type ErrDeleteObjects struct {
	// contains filtered or unexported fields
}

func (*ErrDeleteObjects) Error

func (e *ErrDeleteObjects) Error() string

type ErrDriveClient

type ErrDriveClient struct {
	// contains filtered or unexported fields
}

func (*ErrDriveClient) Error

func (e *ErrDriveClient) Error() string

type ErrDriveUpload

type ErrDriveUpload struct {
	// contains filtered or unexported fields
}

func (*ErrDriveUpload) Error

func (e *ErrDriveUpload) Error() string

type ErrExecQuery added in v0.0.3

type ErrExecQuery struct {
	// contains filtered or unexported fields
}

func (*ErrExecQuery) Error added in v0.0.3

func (e *ErrExecQuery) Error() string

type ErrGetSecret

type ErrGetSecret struct {
	// contains filtered or unexported fields
}

func (*ErrGetSecret) Error

func (e *ErrGetSecret) Error() string

type ErrInvalidPath

type ErrInvalidPath struct {
	// contains filtered or unexported fields
}

func (*ErrInvalidPath) Error

func (e *ErrInvalidPath) Error() string

type ErrInvalidStmt added in v0.0.7

type ErrInvalidStmt struct{}

func (*ErrInvalidStmt) Error added in v0.0.7

func (e *ErrInvalidStmt) Error() string

type ErrListObjects

type ErrListObjects struct {
	// contains filtered or unexported fields
}

func (*ErrListObjects) Error

func (e *ErrListObjects) Error() string

type ErrListTopics added in v0.0.2

type ErrListTopics struct {
	// contains filtered or unexported fields
}

func (*ErrListTopics) Error added in v0.0.2

func (e *ErrListTopics) Error() string

type ErrNewSession added in v0.0.3

type ErrNewSession struct {
	// contains filtered or unexported fields
}

func (*ErrNewSession) Error added in v0.0.3

func (e *ErrNewSession) Error() string

type ErrNewWindow added in v0.0.3

type ErrNewWindow struct {
	// contains filtered or unexported fields
}

func (*ErrNewWindow) Error added in v0.0.3

func (e *ErrNewWindow) Error() string

type ErrNilAWSClient

type ErrNilAWSClient struct {
	// contains filtered or unexported fields
}

func (*ErrNilAWSClient) Error

func (e *ErrNilAWSClient) Error() string

type ErrNilClient

type ErrNilClient struct{}

func (*ErrNilClient) Error

func (e *ErrNilClient) Error() string

type ErrNilConfig

type ErrNilConfig struct{}

func (*ErrNilConfig) Error

func (e *ErrNilConfig) Error() string

type ErrNilDrive

type ErrNilDrive struct{}

func (*ErrNilDrive) Error

func (e *ErrNilDrive) Error() string

type ErrNilPgxPool added in v0.0.3

type ErrNilPgxPool struct{}

func (*ErrNilPgxPool) Error added in v0.0.3

func (e *ErrNilPgxPool) Error() string

type ErrNilPgxTx added in v0.0.3

type ErrNilPgxTx struct{}

func (*ErrNilPgxTx) Error added in v0.0.3

func (e *ErrNilPgxTx) Error() string

type ErrNilToken

type ErrNilToken struct{}

func (*ErrNilToken) Error

func (e *ErrNilToken) Error() string

type ErrNotFound added in v0.0.3

type ErrNotFound struct {
	// contains filtered or unexported fields
}

func (*ErrNotFound) Error added in v0.0.3

func (e *ErrNotFound) Error() string

type ErrOpenFile

type ErrOpenFile struct {
	// contains filtered or unexported fields
}

func (*ErrOpenFile) Error

func (e *ErrOpenFile) Error() string

type ErrProtoMarshal added in v0.0.2

type ErrProtoMarshal struct {
	// contains filtered or unexported fields
}

func (*ErrProtoMarshal) Error added in v0.0.2

func (e *ErrProtoMarshal) Error() string

type ErrPutObject added in v0.0.7

type ErrPutObject struct {
	// contains filtered or unexported fields
}

func (*ErrPutObject) Error added in v0.0.7

func (e *ErrPutObject) Error() string

type ErrQueryRow added in v0.0.3

type ErrQueryRow struct {
	// contains filtered or unexported fields
}

func (*ErrQueryRow) Error added in v0.0.3

func (e *ErrQueryRow) Error() string

type ErrReadCfg added in v0.0.3

type ErrReadCfg struct {
	// contains filtered or unexported fields
}

func (*ErrReadCfg) Error added in v0.0.3

func (e *ErrReadCfg) Error() string

type ErrS3Output

type ErrS3Output struct {
	// contains filtered or unexported fields
}

func (*ErrS3Output) Error

func (e *ErrS3Output) Error() string

type ErrSelectWindow added in v0.0.3

type ErrSelectWindow struct {
	// contains filtered or unexported fields
}

func (*ErrSelectWindow) Error added in v0.0.3

func (e *ErrSelectWindow) Error() string

type ErrSendKeys added in v0.0.3

type ErrSendKeys struct {
	// contains filtered or unexported fields
}

func (*ErrSendKeys) Error added in v0.0.3

func (e *ErrSendKeys) Error() string

type ErrTypeCast

type ErrTypeCast struct {
	// contains filtered or unexported fields
}

func (*ErrTypeCast) Error

func (e *ErrTypeCast) Error() string

type ErrUnmarshalToml added in v0.0.3

type ErrUnmarshalToml struct {
	// contains filtered or unexported fields
}

func (*ErrUnmarshalToml) Error added in v0.0.3

func (e *ErrUnmarshalToml) Error() string

type ErrWebToken

type ErrWebToken struct {
	// contains filtered or unexported fields
}

func (*ErrWebToken) Error

func (e *ErrWebToken) Error() string

type GoogleAdapter

type GoogleAdapter struct {
	// contains filtered or unexported fields
}

func NewGoogleAdapter

func NewGoogleAdapter(tracer trace.Tracer, opts ...GoogleOpt) (*GoogleAdapter, error)

func (*GoogleAdapter) Upload added in v0.0.4

func (a *GoogleAdapter) Upload(ctx context.Context, file io.Reader, name string) error

type GoogleOpt

type GoogleOpt func(a *GoogleAdapter) error

func WithCredentialsJSON

func WithCredentialsJSON(ctx context.Context, source string) GoogleOpt

func WithDriveConn

func WithDriveConn(ctx context.Context) GoogleOpt

func WithGoogleSpanAttrs added in v0.0.7

func WithGoogleSpanAttrs(attrs ...attribute.KeyValue) GoogleOpt

type KafkaAdapter added in v0.0.2

type KafkaAdapter struct {
	// contains filtered or unexported fields
}

func NewKafkaAdapter added in v0.0.2

func NewKafkaAdapter(logger *slog.Logger, tracer trace.Tracer, opts ...KafkaOpt) (*KafkaAdapter, error)

NewKafkaAdapter creates a new kafka adapter. Adapters should be configured to either produce or consume, but not both

func (*KafkaAdapter) Close added in v0.0.2

func (a *KafkaAdapter) Close() error

Close closes the kafka client

func (*KafkaAdapter) Consume added in v0.0.2

func (a *KafkaAdapter) Consume(ctx context.Context, consumer KafkaConsumer)

Consume uses the supplied consumer to process kafka records from the configured topic

func (*KafkaAdapter) CreateTopic added in v0.0.2

func (a *KafkaAdapter) CreateTopic(ctx context.Context, topic string) error

CreateTopic creates a kafka topic

func (*KafkaAdapter) Send added in v0.0.2

Send sends the supplied kafka record to the configured topic

type KafkaConsumer added in v0.0.2

type KafkaConsumer interface {
	Process(ctx context.Context, record *kgo.Record) error
}

type KafkaOpt added in v0.0.2

type KafkaOpt func(a *KafkaAdapter) error

func WithConsumer added in v0.0.2

func WithConsumer(topic string, groupname string, brokers []string) KafkaOpt

func WithKafkaSpanAttrs added in v0.0.7

func WithKafkaSpanAttrs(attrs ...attribute.KeyValue) KafkaOpt

func WithProducer added in v0.0.2

func WithProducer(topic string, brokers []string) KafkaOpt

type ListObjectsV2Pager

type ListObjectsV2Pager interface {
	HasMorePages() bool
	NextPage(ctx context.Context, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
}

type ObjectNotExistsWaiter

type ObjectNotExistsWaiter interface {
	Wait(ctx context.Context, params *s3.HeadObjectInput, maxWaitDur time.Duration, optFns ...func(*s3.ObjectNotExistsWaiterOptions)) error
}

type PgxPool added in v0.0.3

type PgxPool interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Query(ctx context.Context, sql string, args ...interface{}) (pgx.Rows, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
	Exec(ctx context.Context, sql string, args ...interface{}) (pgconn.CommandTag, error)
}

type PgxTx added in v0.0.3

type PgxTx interface {
	Commit(ctx context.Context) error
	Rollback(ctx context.Context) error
}

type PostgresAdapter added in v0.0.3

type PostgresAdapter[T any] struct {
	// contains filtered or unexported fields
}

func NewPostgresAdapter added in v0.0.3

func NewPostgresAdapter[T any](pool PgxPool, logger *slog.Logger, tracer trace.Tracer, opts ...PostgresOpt[T]) *PostgresAdapter[T]

NewPostgresAdapter creates a new PostgresAdapter

func (*PostgresAdapter[T]) Commit added in v0.0.3

func (a *PostgresAdapter[T]) Commit(ctx context.Context) error

Commit commits the transaction after first checking if the context has been canceled

func (*PostgresAdapter[T]) ConnectionPool added in v0.0.3

func (a *PostgresAdapter[T]) ConnectionPool() PgxPool

ConnectionPool returns the underlying pgxpool

func (*PostgresAdapter[T]) Delete added in v0.0.3

func (a *PostgresAdapter[T]) Delete(ctx context.Context, sql string, args map[string]interface{}) error

Delete deletes the supplied row

func (*PostgresAdapter[T]) Exec added in v0.0.7

func (a *PostgresAdapter[T]) Exec(ctx context.Context, sql string, args map[string]interface{}) (int64, error)

Exec executes the supplied sql statement and returns the number of rows affected

func (*PostgresAdapter[T]) Insert added in v0.0.3

func (a *PostgresAdapter[T]) Insert(ctx context.Context, sql string, args map[string]interface{}) (int, error)

Insert creates a new row returns the id

func (*PostgresAdapter[T]) NewTransactionAdapter added in v0.0.3

func (a *PostgresAdapter[T]) NewTransactionAdapter(ctx context.Context) (*PostgresAdapter[T], error)

NewTransactionAdapter creates an adapter for executing transactions

func (*PostgresAdapter[T]) Rollback added in v0.0.3

func (a *PostgresAdapter[T]) Rollback(ctx context.Context) error

Rollback initiates a transaction rollback

func (*PostgresAdapter[T]) RowExists added in v0.0.3

func (a *PostgresAdapter[T]) RowExists(ctx context.Context, sql string, args map[string]interface{}) (bool, error)

func (*PostgresAdapter[T]) Select added in v0.0.3

func (a *PostgresAdapter[T]) Select(ctx context.Context, sql string, args map[string]interface{}) ([]T, error)

type PostgresOpt added in v0.0.3

type PostgresOpt[T any] func(a *PostgresAdapter[T])

func WithPgxTx added in v0.0.3

func WithPgxTx[T any](tx PgxTx) PostgresOpt[T]

WithPgxTx sets the transaction adapter

func WithPostgresSpanAttrs added in v0.0.7

func WithPostgresSpanAttrs[T any](attrs ...attribute.KeyValue) PostgresOpt[T]

type S3Client

type S3Client interface {
	HeadObject(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error)
	GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
	PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
	ListObjectsV2(ctx context.Context, params *s3.ListObjectsV2Input, optFns ...func(*s3.Options)) (*s3.ListObjectsV2Output, error)
	DeleteObjects(ctx context.Context, params *s3.DeleteObjectsInput, optFns ...func(*s3.Options)) (*s3.DeleteObjectsOutput, error)
}

type SecretsManagerClient

type SecretsManagerClient interface {
	GetSecretValue(ctx context.Context, params *secretsmanager.GetSecretValueInput, optFns ...func(*secretsmanager.Options)) (*secretsmanager.GetSecretValueOutput, error)
}

type TmuxAdapter added in v0.0.3

type TmuxAdapter struct {
	// contains filtered or unexported fields
}

func NewTmuxAdapter added in v0.0.3

func NewTmuxAdapter(adapter Command) *TmuxAdapter

NewTmuxAdapter creates a tmux adapter

func (*TmuxAdapter) AttachSession added in v0.0.3

func (a *TmuxAdapter) AttachSession(ctx context.Context, session string) error

AttachSession attempts attaching to a tmux session

func (*TmuxAdapter) HasSession added in v0.0.3

func (a *TmuxAdapter) HasSession(ctx context.Context, session string) int

HasSession checks for an already existing tmux session

func (*TmuxAdapter) NewSession added in v0.0.3

func (a *TmuxAdapter) NewSession(ctx context.Context, name string) error

NewSession creates a new tmux session

func (*TmuxAdapter) NewWindow added in v0.0.3

func (a *TmuxAdapter) NewWindow(ctx context.Context, session string, name string) error

NewWindow creates a new tmux window

func (*TmuxAdapter) SelectWindow added in v0.0.3

func (a *TmuxAdapter) SelectWindow(ctx context.Context, session string, window string) error

SelectWindow selects a tmux window

func (*TmuxAdapter) SendKeys added in v0.0.5

func (a *TmuxAdapter) SendKeys(ctx context.Context, cmd []string, session string, window string) error

SendKeys executes the supplied command

type TomlAdapter added in v0.0.3

type TomlAdapter[T any] struct {
	Config T
}

func NewTomlAdapter added in v0.0.3

func NewTomlAdapter[T any]() *TomlAdapter[T]

NewTomlAdapter creates a toml adapter

func (*TomlAdapter[T]) LoadConfig added in v0.0.3

func (a *TomlAdapter[T]) LoadConfig(filename string) error

LoadConfig attempts to read a toml file in the current directory and returns a config

type ZipAdapter

type ZipAdapter struct{}

func NewZipAdapter

func NewZipAdapter() *ZipAdapter

func (*ZipAdapter) Unzip

func (a *ZipAdapter) Unzip(ctx context.Context, src string, dst string) error

func (*ZipAdapter) Zip

func (a *ZipAdapter) Zip(ctx context.Context, src string, filename string, dst io.Writer) error

Jump to

Keyboard shortcuts

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