proxy

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func NewBarProxy(target service.Bar, middlewares map[string][]func(func(context.Context) error) func(context.Context) error) *BarProxy

func (*BarProxy) Create

func (p *BarProxy) Create(_userCtx context.Context, dto dto.Bar) (int, error)

func (*BarProxy) Find

func (p *BarProxy) Find(_userCtx context.Context, id int) (*entity.Bar, error)

type BarProxyMiddleware

type BarProxyMiddleware func(func(context.Context) error) func(context.Context) error

helper for BarProxy middleware

type BarProxyMiddlewareByAnnotation

type BarProxyMiddlewareByAnnotation map[string]BarProxyMiddlewares

helper for BarProxy middleware map about middlewares by aannotation

func (BarProxyMiddlewareByAnnotation) To

convert BarProxy middleware map to raw type

type BarProxyMiddlewares

type BarProxyMiddlewares []BarProxyMiddleware

func (BarProxyMiddlewares) To

func (a BarProxyMiddlewares) To() []func(func(context.Context) error) func(context.Context) error

convert BarProxy middleware to raw type

type Foo2Proxy

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

implement proxy for Foo2

func NewFoo2Proxy

func NewFoo2Proxy(target service.Foo2, middlewares map[string][]func(func(context.Context) error) func(context.Context) error) *Foo2Proxy

func (*Foo2Proxy) Create

func (p *Foo2Proxy) Create(_userCtx context.Context, dto dto.Foo) (int, error)

func (*Foo2Proxy) Find

func (p *Foo2Proxy) Find(_userCtx context.Context, id int) (*entity.Foo, error)

func (*Foo2Proxy) FooBara

func (p *Foo2Proxy) FooBara(_userCtx context.Context, dto dto.Foo) error

type Foo2ProxyMiddleware

type Foo2ProxyMiddleware func(func(context.Context) error) func(context.Context) error

helper for Foo2Proxy middleware

type Foo2ProxyMiddlewareByAnnotation

type Foo2ProxyMiddlewareByAnnotation map[string]Foo2ProxyMiddlewares

helper for Foo2Proxy middleware map about middlewares by aannotation

func (Foo2ProxyMiddlewareByAnnotation) To

convert Foo2Proxy middleware map to raw type

type Foo2ProxyMiddlewares

type Foo2ProxyMiddlewares []Foo2ProxyMiddleware

func (Foo2ProxyMiddlewares) To

func (a Foo2ProxyMiddlewares) To() []func(func(context.Context) error) func(context.Context) error

convert Foo2Proxy middleware to raw type

type FooBarProxy

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

implement proxy for FooBar

func NewFooBarProxy

func NewFooBarProxy(target service.FooBar, middlewares map[string][]func(func(context.Context) error) func(context.Context) error) *FooBarProxy

func (*FooBarProxy) Create

func (p *FooBarProxy) Create(_userCtx context.Context, foo dto.Foo, bar dto.Bar) (int, int, error)

func (*FooBarProxy) Find

func (p *FooBarProxy) Find(_userCtx context.Context, fooID int, barID int) (*entity.Foo, *entity.Bar, error)

type FooBarProxyMiddleware

type FooBarProxyMiddleware func(func(context.Context) error) func(context.Context) error

helper for FooBarProxy middleware

type FooBarProxyMiddlewareByAnnotation

type FooBarProxyMiddlewareByAnnotation map[string]FooBarProxyMiddlewares

helper for FooBarProxy middleware map about middlewares by aannotation

func (FooBarProxyMiddlewareByAnnotation) To

convert FooBarProxy middleware map to raw type

type FooBarProxyMiddlewares

type FooBarProxyMiddlewares []FooBarProxyMiddleware

func (FooBarProxyMiddlewares) To

func (a FooBarProxyMiddlewares) To() []func(func(context.Context) error) func(context.Context) error

convert FooBarProxy middleware to raw type

type FooProxy

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

implement proxy for Foo

func NewFooProxy

func NewFooProxy(target service.Foo, middlewares map[string][]func(func(context.Context) error) func(context.Context) error) *FooProxy

func (*FooProxy) Create

func (p *FooProxy) Create(_userCtx context.Context, dto dto.Foo) (int, error)

func (*FooProxy) Find

func (p *FooProxy) Find(_userCtx context.Context, id int) (*entity.Foo, error)

func (*FooProxy) FooBara

func (p *FooProxy) FooBara(_userCtx context.Context, dto dto.Foo) error

type FooProxyMiddleware

type FooProxyMiddleware func(func(context.Context) error) func(context.Context) error

helper for FooProxy middleware

type FooProxyMiddlewareByAnnotation

type FooProxyMiddlewareByAnnotation map[string]FooProxyMiddlewares

helper for FooProxy middleware map about middlewares by aannotation

func (FooProxyMiddlewareByAnnotation) To

convert FooProxy middleware map to raw type

type FooProxyMiddlewares

type FooProxyMiddlewares []FooProxyMiddleware

func (FooProxyMiddlewares) To

func (a FooProxyMiddlewares) To() []func(func(context.Context) error) func(context.Context) error

convert FooProxy middleware to raw type

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.

Jump to

Keyboard shortcuts

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