transaction

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2020 License: BSD-3-Clause Imports: 13 Imported by: 1

README

Transaction

Package transaction provides a reusable component for creating and closing a request scope in gRPC.

Documentation

Overview

Package transaction provides a reusable component for creating and closing a request scope in gRPC.

Index

Constants

View Source
const (
	// ErrNotEnoughTime is returned as a gRPC error message.
	ErrNotEnoughTime = "Not enough time in context"
	// ErrDB is returned as a gRPC error message.
	ErrDB = "Database error"
	// ErrAuth is returned as a gRPC error message.
	ErrAuth = "Authentication server error"
	// ErrGroup is returned as a gRPC error message.
	ErrGroup = "User not in required group"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Ctx      context.Context
	Tx       boil.ContextTransactor
	Log      *logrus.Entry
	ReadOnly bool
	Claims   *jwt.Claims
	// contains filtered or unexported fields
}

Request holds a database transaction, request context and a logrus entry.

func New

func New(ctx context.Context, log *logrus.Entry, mdb *multidb.MultiDB, readOnly bool, routines ...int) (*Request, error)

New Request opens a transaction on mdb. If the transaction is readonly, routines amount of Nodes will be requested.

func (*Request) Commit

func (rt *Request) Commit() error

Commit the current transaction

func (*Request) Done

func (rt *Request) Done()

Done Rollbacks an open transaction and cancels the Request Context. Done is meant to be deferred and errors are logged, not returned.

func (*Request) EnoughTime

func (rt *Request) EnoughTime(need time.Duration) error

EnoughTime checks if the context is valid and has enough time available.

type Verificator added in v0.2.0

type Verificator struct {
	verify.Verificator
}

Verificator can be used to open authenticated transactions.

func NewVerificator added in v0.2.0

func NewVerificator(ctx context.Context, entry *logrus.Entry, target string, audiences ...string) (*Verificator, error)

NewVerificator dials the target authentication gRPC server and keeps retrying untill the context expires.

func (*Verificator) NewAuth added in v0.2.0

func (v *Verificator) NewAuth(ctx context.Context, entry *logrus.Entry, mdb *multidb.MultiDB, readOnly bool, max int, token string, groups ...string) (*Request, error)

NewAuth opens an authenticated transaction.

Jump to

Keyboard shortcuts

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