Documentation
¶
Index ¶
- Variables
- func TxMiddleware(creator TransactionFactory) func(func(c context.Context) error) func(context.Context) error
- type BarProxy
- type BarProxyMiddleware
- type BarProxyMiddlewareByAnnotation
- type BarProxyMiddlewares
- type Foo2Proxy
- type Foo2ProxyMiddleware
- type Foo2ProxyMiddlewareByAnnotation
- type Foo2ProxyMiddlewares
- type FooBarProxy
- type FooBarProxyMiddleware
- type FooBarProxyMiddlewareByAnnotation
- type FooBarProxyMiddlewares
- type FooProxy
- type FooProxyMiddleware
- type FooProxyMiddlewareByAnnotation
- type FooProxyMiddlewares
- type Transaction
- type TransactionFactory
Constants ¶
This section is empty.
Variables ¶
var ( ErrNilTransactionFactory = errors.New("transaction factory is nil") ErrRollbackTransaction = errors.New("rollback transaction") )
Functions ¶
func TxMiddleware ¶
func TxMiddleware(creator TransactionFactory) func(func(c context.Context) error) func(context.Context) error
TxMiddleware is a function that returns a middleware that manages transactions. The middleware creates a new transaction if the transaction is not set in the context. If the transaction is set in the context, the middleware manages the transaction.
the middleware is used as follows:
txFatory := func() (proxy.Transaction, error) {
tx, err := NewUserTransaction()
if err != nil {
return nil, err
}
return tx, nil
}
txMiddleware := proxy.TxMiddleware(txFatory)
Types ¶
type BarProxy ¶
type BarProxy struct {
// contains filtered or unexported fields
}
implement proxy for Bar
func NewBarProxy ¶
type BarProxyMiddleware ¶
helper for BarProxy middleware
type BarProxyMiddlewareByAnnotation ¶
type BarProxyMiddlewareByAnnotation map[string]BarProxyMiddlewares
helper for BarProxy middleware map about middlewares by aannotation
type BarProxyMiddlewares ¶
type BarProxyMiddlewares []BarProxyMiddleware
type Foo2Proxy ¶
type Foo2Proxy struct {
// contains filtered or unexported fields
}
implement proxy for Foo2
func NewFoo2Proxy ¶
type Foo2ProxyMiddleware ¶
helper for Foo2Proxy middleware
type Foo2ProxyMiddlewareByAnnotation ¶
type Foo2ProxyMiddlewareByAnnotation map[string]Foo2ProxyMiddlewares
helper for Foo2Proxy middleware map about middlewares by aannotation
type Foo2ProxyMiddlewares ¶
type Foo2ProxyMiddlewares []Foo2ProxyMiddleware
type FooBarProxy ¶
type FooBarProxy struct {
// contains filtered or unexported fields
}
implement proxy for FooBar
func NewFooBarProxy ¶
type FooBarProxyMiddleware ¶
helper for FooBarProxy middleware
type FooBarProxyMiddlewareByAnnotation ¶
type FooBarProxyMiddlewareByAnnotation map[string]FooBarProxyMiddlewares
helper for FooBarProxy middleware map about middlewares by aannotation
type FooBarProxyMiddlewares ¶
type FooBarProxyMiddlewares []FooBarProxyMiddleware
type FooProxy ¶
type FooProxy struct {
// contains filtered or unexported fields
}
implement proxy for Foo
func NewFooProxy ¶
type FooProxyMiddleware ¶
helper for FooProxy middleware
type FooProxyMiddlewareByAnnotation ¶
type FooProxyMiddlewareByAnnotation map[string]FooProxyMiddlewares
helper for FooProxy middleware map about middlewares by aannotation
type FooProxyMiddlewares ¶
type FooProxyMiddlewares []FooProxyMiddleware
type Transaction ¶
type Transaction interface {
// Begin begins the transaction.
Begin() error
// Commit commits the transaction.
Commit() error
// Rollback rolls back the transaction.
Rollback() error
// Regist and returns a context with the transaction.
Regist(c context.Context) context.Context
// From sets the transaction from the context.
From(c context.Context) error
}
Transaction is an interface that defines the methods to manage transactions. User should implement this interface to manage transactions.
type TransactionFactory ¶
type TransactionFactory func() (Transaction, error)
NewTransaction is a function that creates a new transaction. User should implement this function to create a new transaction.
txFatory := func() (proxy.Transaction, error) {
tx, err := NewUserTransaction()
if err != nil {
return nil, err
}
return tx, nil
}
The function should return a new transaction and an error.