usecasex

package
v0.0.0-...-5cbc45b Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const IDErrTransaction = "transaction error"

Variables

View Source
var ErrPolicyVioration = errors.New("policy violation")
View Source
var (
	ErrTransaction = rerror.WrapE(&i18n.Message{ID: IDErrTransaction}, rawErrTransaction)
)

Functions

func DoTransaction

func DoTransaction(ctx context.Context, t Transaction, retry int, fn func(ctx context.Context) error) (err error)

func Run

func Run(ctx context.Context, h Handler, m ...Middleware) (err error)

func Run1

func Run1[A any](ctx context.Context, h Handler1[A], m ...Middleware) (a A, err error)

func Run2

func Run2[A, B any](ctx context.Context, h Handler2[A, B], m ...Middleware) (a A, b B, err error)

func Run3

func Run3[A, B, C any](ctx context.Context, h Handler3[A, B, C], m ...Middleware) (a A, b B, c C, err error)

Types

type Ctx

type Ctx interface {
	Context() context.Context
	SetContext(ctx context.Context)
}

type Cursor

type Cursor string

func CursorFromRef

func CursorFromRef(c *string) *Cursor

func (*Cursor) CopyRef

func (c *Cursor) CopyRef() *Cursor

func (Cursor) Ref

func (c Cursor) Ref() *Cursor

func (*Cursor) StringRef

func (c *Cursor) StringRef() *string

type CursorPagination

type CursorPagination struct {
	Before *Cursor `json:"before"`
	After  *Cursor `json:"after"`
	First  *int64  `json:"first"`
	Last   *int64  `json:"last"`
}

CursorPagination is a struct for Relay-Style Cursor Pagination ref: https://www.apollographql.com/docs/react/features/pagination/#relay-style-cursor-pagination

func (*CursorPagination) Clone

func (p *CursorPagination) Clone() *CursorPagination

func (CursorPagination) Wrap

func (p CursorPagination) Wrap() *Pagination

type Handler

type Handler func(ctx context.Context) error

type Handler1

type Handler1[A any] func(ctx context.Context) (A, error)

type Handler2

type Handler2[A, B any] func(ctx context.Context) (A, B, error)

type Handler3

type Handler3[A, B, C any] func(ctx context.Context) (A, B, C, error)

type Middleware

type Middleware func(next MiddlewareHandler) MiddlewareHandler

func ComposeMiddleware

func ComposeMiddleware(m ...Middleware) Middleware

func UpdateContext

func UpdateContext(f func(ctx context.Context) context.Context) Middleware

type MiddlewareHandler

type MiddlewareHandler func(ctx context.Context) (context.Context, error)

func ApplyMiddleware

func ApplyMiddleware(h MiddlewareHandler, middleware ...Middleware) MiddlewareHandler

type NopTransaction

type NopTransaction struct {
	BeginError  error
	CommitError error
	// contains filtered or unexported fields
}

func (*NopTransaction) Begin

func (t *NopTransaction) Begin(ctx context.Context) (Tx, error)

func (*NopTransaction) IsCommitted

func (t *NopTransaction) IsCommitted() bool

type NopTx

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

func (*NopTx) Commit

func (t *NopTx) Commit()

func (*NopTx) Context

func (t *NopTx) Context() context.Context

func (*NopTx) End

func (t *NopTx) End(_ context.Context) error

func (*NopTx) IsCommitted

func (t *NopTx) IsCommitted() bool

type OffsetPagination

type OffsetPagination struct {
	Offset int64 `json:"offset"`
	Limit  int64 `json:"limit"`
}

func (OffsetPagination) Wrap

func (p OffsetPagination) Wrap() *Pagination

type OperatableWorkspace

type OperatableWorkspace struct {
	Workspace workspace.ID
	Role      workspace.Role
}

type Operator

type Operator struct {
	Workspaces []OperatableWorkspace
}

type PageInfo

type PageInfo struct {
	TotalCount      int64
	StartCursor     *Cursor
	EndCursor       *Cursor
	HasNextPage     bool
	HasPreviousPage bool
}

func EmptyPageInfo

func EmptyPageInfo() *PageInfo

func NewPageInfo

func NewPageInfo(totalCount int64, startCursor, endCursor *Cursor, hasNextPage, hasPreviousPage bool) *PageInfo

func (*PageInfo) Clone

func (p *PageInfo) Clone() *PageInfo

func (*PageInfo) OrEmpty

func (p *PageInfo) OrEmpty() *PageInfo

type Pagination

type Pagination struct {
	Cursor *CursorPagination
	Offset *OffsetPagination
}

func (*Pagination) Clone

func (p *Pagination) Clone() *Pagination

type Sort

type Sort struct {
	Key      string
	Reverted bool
}

type Transaction

type Transaction interface {
	Begin(context.Context) (Tx, error)
}

type Tx

type Tx interface {
	// Context returns a context suitable for use under transaction.
	Context() context.Context
	// Commit informs the Tx to commit when End() is called.
	// If this was not called once, rollback is done when End() is called.
	Commit()
	// End finishes the transaction and do commit if Commit() was called once, or else do rollback.
	// This method is supposed to be called in the uscase layer using defer.
	End(ctx context.Context) error
	// IsCommitted returns true if the Tx is marked as committed.
	IsCommitted() bool
}

type TxUsecase

type TxUsecase struct {
	Transaction Transaction
}

func (TxUsecase) UseTx

func (t TxUsecase) UseTx() Middleware

func (TxUsecase) UseTxWithRetries

func (t TxUsecase) UseTxWithRetries(retry int) Middleware

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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