internal

package
v1.9.5 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//TransactionKey for transaction DB handles in the first-level cache
	TransactionKey = "freedom_local_transaction_db"
)
View Source
const (
	// WorkerKey specify where is the Worker should be located in Context
	WorkerKey = "STORE-WORKER-KEY"
)

Variables

This section is empty.

Functions

func ConvertAssign

func ConvertAssign(dest, src interface{}) error

ConvertAssign .

func HandleBusMiddleware

func HandleBusMiddleware(worker Worker)

HandleBusMiddleware Process the message bus middleware.

func InSlice

func InSlice(array interface{}, item interface{}) bool

InSlice .

func NewMap

func NewMap(dst interface{}) error

NewMap .

func NewSlice

func NewSlice(dsc interface{}, len int) error

NewSlice .

func Prepare

func Prepare(f func(Initiator))

Prepare A prepared function is passed in for initialization.

func SliceDelete

func SliceDelete(arr interface{}, indexArr ...int) error

SliceDelete delete the specified subscript element of the array

Types

type Application

type Application struct {

	// TODO(coco):
	//  Here is bad smell I felt, so we shouldn't export this member. Considering
	//  sets this member unexported in the future.
	//
	// IrisApp is an iris application
	IrisApp *IrisApplication

	// Database represents a database connection
	Database struct {
		Install func() (db interface{})
		// contains filtered or unexported fields
	}

	// Cache represents a redis client
	Cache struct {
		Install func() (client redis.Cmdable)
		// contains filtered or unexported fields
	}

	// Middleware is a set that satisfies the iris handler's definition
	Middleware []IrisHandler

	// Prometheus .
	Prometheus *Prometheus
	// contains filtered or unexported fields
}

Application represents a manager of freedom.

func NewApplication

func NewApplication() *Application

NewApplication Creates an instance of Application exactly once while the program is running.

func (*Application) BindBooting added in v1.8.9

func (app *Application) BindBooting(f func(bootManager BootManager))

BindBooting Adds a builder function which builds a BootManager.

func (*Application) BindController

func (app *Application) BindController(relativePath string, controller IrisController, handlers ...IrisHandler)

BindController accepts a string with the route path, an IrisController, and one or more IrisHandler. BindController resolves the application's dependencies, and creates an IrisRouter and an IrisMVCApplication. the IrisMVCApplication would be attached on IrisRouter and the EventBus after it has created.

func (*Application) BindControllerByParty

func (app *Application) BindControllerByParty(router IrisParty, controller interface{})

BindControllerByParty accepts an IrisRouter and an IrisController. BindControllerByParty resolves the application's dependencies, and creates an IrisRouter and an IrisMVCApplication. the IrisMVCApplication would be attached on IrisRouter and the EventBus after it has created.

func (*Application) BindControllerWithParty added in v1.8.9

func (app *Application) BindControllerWithParty(router IrisParty, controller IrisController)

BindControllerWithParty accepts an IrisRouter and an IrisController. BindControllerWithParty resolves the application's dependencies, and creates an IrisRouter and an IrisMVCApplication. the IrisMVCApplication would be attached on IrisRouter and the EventBus after it has created.

func (*Application) BindFactory added in v1.7.11

func (app *Application) BindFactory(f interface{})

BindFactory Bind a function that creates the repository.

func (*Application) BindInfra

func (app *Application) BindInfra(single bool, com interface{})

BindInfra Bind a function that creates the repository infrastructure.

func (*Application) BindRepository

func (app *Application) BindRepository(f interface{})

BindRepository Bind a function that creates the repository.

func (*Application) BindService

func (app *Application) BindService(f interface{})

BindService Bind a function that creates the service.

func (*Application) CreateParty

func (app *Application) CreateParty(relativePath string, handlers ...IrisHandler) IrisParty

CreateParty accepts a string with the route path, and one or more IrisHandler. CreateParty makes a new path by concatenating the application-level router's prefix and the specified route path, creates an IrisRouter with the new path and the those specified IrisHandler, and returns the IrisRouter.

func (*Application) EventsPath

func (app *Application) EventsPath(infra interface{}) map[string]string

EventsPath Gets the event name and HTTP routing address for Listen.

func (*Application) FetchInfra added in v1.8.9

func (app *Application) FetchInfra(ctx IrisContext, com interface{})

FetchInfra accepts an IrisContext and a pointer to the typed service. GetInfra looks up a service from the InfraPool by the type of the pointer and fill the pointer with the service.

func (*Application) FetchService added in v1.8.9

func (app *Application) FetchService(ctx IrisContext, service interface{})

FetchService accepts an IrisContext and a pointer to the typed service. FetchService looks up a service from the ServicePool by the type of the pointer and fill the pointer with the service.

func (*Application) FetchSingleInfra added in v1.8.9

func (app *Application) FetchSingleInfra(com interface{}) bool

FetchSingleInfra .

func (*Application) GetInfra

func (app *Application) GetInfra(ctx IrisContext, com interface{})

GetInfra accepts an IrisContext and a pointer to the typed service. GetInfra looks up a service from the InfraPool by the type of the pointer and fill the pointer with the service.

func (*Application) GetService

func (app *Application) GetService(ctx IrisContext, service interface{})

GetService accepts an IrisContext and a pointer to the typed service. GetService looks up a service from the ServicePool by the type of the pointer and fill the pointer with the service.

func (*Application) GetServiceLocator added in v1.8.8

func (app *Application) GetServiceLocator() *ServiceLocatorImpl

GetServiceLocator . Because of ambiguous naming, I've been create ServiceLocator as an alternative. Considering remove this function in the future.

func (*Application) InjectController

func (app *Application) InjectController(f Dependency)

InjectController adds a Dependency for iris controller. Because of ambiguous naming, I've been create InjectIntoController as an alternative. Considering remove this function in the future.

func (*Application) InjectIntoController added in v1.8.8

func (app *Application) InjectIntoController(f Dependency)

InjectIntoController Adds a Dependency for iris controller.

func (*Application) InstallBusMiddleware

func (app *Application) InstallBusMiddleware(handle ...BusHandler)

InstallBusMiddleware Install the middleware for the message bus.

func (*Application) InstallCustom added in v1.8.9

func (app *Application) InstallCustom(f func() interface{})

InstallCustom Install a custom data source. A function that returns the Interface type is passed in as a handle to the custom data sources.

func (*Application) InstallDB added in v1.7.13

func (app *Application) InstallDB(f func() interface{})

InstallDB Install the database. A function that returns the Interface type is passed in as a handle to the database.

func (*Application) InstallMiddleware

func (app *Application) InstallMiddleware(handler IrisHandler)

InstallMiddleware Install the middleware for http routing globally.

func (*Application) InstallParty

func (app *Application) InstallParty(prefixPath string)

InstallParty assigns specified prefix to the application-level router. Because of ambiguous naming, I've been create SetPrefixPath as an alternative. Considering remove this function in the future.

func (*Application) InstallRedis

func (app *Application) InstallRedis(f func() (client redis.Cmdable))

InstallRedis Install the redis. A function that returns the redis.Cmdable is passed in as a handle to the client.

func (*Application) InstallSerializer

func (app *Application) InstallSerializer(marshal func(v interface{}) ([]byte, error), unmarshal func(data []byte, v interface{}) error)

InstallSerializer .

func (*Application) Iris

func (app *Application) Iris() *IrisApplication

Iris Go back to the iris app.

func (*Application) ListenEvent

func (app *Application) ListenEvent(eventName string, objectMethod string, appointInfra ...interface{})

ListenEvent You need to listen for message events using http agents. eventName is the name of the event. objectMethod is the controller that needs to be received. appointInfra can delegate infrastructure.

func (*Application) Logger

func (app *Application) Logger() *golog.Logger

Logger Return to global logger.

func (*Application) NewAutoTLSRunner added in v1.8.5

func (app *Application) NewAutoTLSRunner(addr string, domain string, email string, configurators ...IrisHostConfigurator) IrisRunner

NewAutoTLSRunner can be used as an argument for the `Run` method. It will start the Application's secure server using certifications created on the fly by the "autocert" golang/x package, so localhost may not be working, use it at "production" machine.

Addr should have the form of host:port, i.e mydomain.com:443.

The whitelisted domains are separated by whitespace in "domain" argument, i.e "8tree.net", can be different than "addr". If empty, all hosts are currently allowed. This is not recommended, as it opens a potential attack where clients connect to a server by IP address and pretend to be asking for an incorrect host name. Manager will attempt to obtain a certificate for that host, incorrectly, eventually reaching the CA's rate limit for certificate requests and making it impossible to obtain actual certificates.

For an "e-mail" use a non-public one, letsencrypt needs that for your own security.

Note: `AutoTLS` will start a new server for you which will redirect all http versions to their https, including subdomains as well.

Last argument is optional, it accepts one or more `func(*host.Configurator)` that are being executed on that specific host that this function will create to start the server. Via host configurators you can configure the back-end host supervisor, i.e to add events for shutdown, serve or error. Look at the `ConfigureHost` too.

func (*Application) NewH2CRunner added in v1.8.5

func (app *Application) NewH2CRunner(addr string, configurators ...IrisHostConfigurator) IrisRunner

NewH2CRunner create a Runner for H2C . intercepting any h2c traffic. If a request is an h2c connection, it's hijacked and redirected to s.ServeConn. Otherwise the returned Handler just forwards requests to h. This works because h2c is designed to be parseable as valid HTTP/1, but ignored by any HTTP server that does not handle h2c. Therefore we leverage the HTTP/1 compatible parts of the Go http library to parse and recognize h2c requests. Once a request is recognized as h2c, we hijack the connection and convert it to an HTTP/2 connection which is understandable to s.ServeConn. (s.ServeConn understands HTTP/2 except for the h2c part of it.)

func (*Application) NewRunner added in v1.8.5

func (app *Application) NewRunner(addr string, configurators ...IrisHostConfigurator) IrisRunner

NewRunner can be used as an argument for the `Run` method. It accepts a host address which is used to build a server and a listener which listens on that host and port.

Addr should have the form of host:port, i.e localhost:8080 or :8080.

Second argument is optional, it accepts one or more `func(*host.Configurator)` that are being executed on that specific host that this function will create to start the server. Via host configurators you can configure the back-end host supervisor, i.e to add events for shutdown, serve or error.

func (*Application) NewTLSRunner added in v1.8.5

func (app *Application) NewTLSRunner(addr string, certFile, keyFile string, configurators ...IrisHostConfigurator) IrisRunner

NewTLSRunner can be used as an argument for the `Run` method. It will start the Application's secure server.

Use it like you used to use the http.ListenAndServeTLS function.

Addr should have the form of host:port, i.e localhost:443 or :443. CertFile & KeyFile should be filenames with their extensions.

Second argument is optional, it accepts one or more `func(*host.Configurator)` that are being executed on that specific host that this function will create to start the server. Via host configurators you can configure the back-end host supervisor, i.e to add events for shutdown, serve or error. An example of this use case can be found at:

func (*Application) RegisterShutdown added in v1.8.0

func (app *Application) RegisterShutdown(f func())

RegisterShutdown Register an inflatable callback function.

func (*Application) Run

func (app *Application) Run(runner IrisRunner, conf IrisConfiguration)

Run accepts an IrisRunner and an IrisConfiguration. Run initializes the middleware and the infrastructure of the application likes database connection, cache, repository and etc. , and serving an iris application as the HTTP server to handle the incoming requests.

func (*Application) SetPrefixPath added in v1.8.8

func (app *Application) SetPrefixPath(prefixPath string)

SetPrefixPath assigns specified prefix to the application-level router.

func (*Application) SubRouter added in v1.8.8

func (app *Application) SubRouter(relativePath string, handlers ...IrisHandler) IrisParty

SubRouter accepts a string with the route path, and one or more IrisHandler. SubRouter makes a new path by concatenating the application-level router's prefix and the specified route path, creates an IrisRouter with the new path and the those specified IrisHandler, and returns the IrisRouter.

type BeginRequest

type BeginRequest interface {
	BeginRequest(Worker Worker)
}

BeginRequest Requests to start the interface, and the call is triggered when the instance is implemented.

type BootManager added in v1.8.9

type BootManager interface {
	// Go back to the iris app.
	Iris() *iris.Application
	// Gets a single-case component.
	FetchSingleInfra(infra interface{}) bool
	// Gets the event name and HTTP routing address for Listen.
	EventsPath(infra interface{}) map[string]string
	// Register an inflatable callback function.
	RegisterShutdown(func())
}

BootManager can be used to launch in the application.

type Bus

type Bus struct {
	http.Header
}

Bus Message bus, using http header to pass through data.

func (*Bus) Add

func (b *Bus) Add(key, obj string)

Add .

func (*Bus) Del

func (b *Bus) Del(key string)

Del .

func (*Bus) Get

func (b *Bus) Get(key string) string

Get .

func (*Bus) Set

func (b *Bus) Set(key, obj string)

Set .

type BusHandler

type BusHandler func(Worker)

BusHandler The middleware type of the message bus. .

type Dependency added in v1.8.8

type Dependency = interface{}

Dependency is a function which represents a dependency of the application. A valid definition of dependency should like:

func foo(ctx iris.Context) Bar {
  return Bar{}
}

Example: If you want to inject a `Foo` into somewhere, you could written:

func (ctx iris.Context) Foo {
  return NewFoo() // you'd replace NewFoo() with your own logic for creating Foo.
}

type DomainEvent added in v1.8.6

type DomainEvent interface {
	//The only noun used to identify an event.
	Topic() string
	//Set the property.
	SetPrototypes(map[string]interface{})
	//Read the property.
	GetPrototypes() map[string]interface{}
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	//The unique ID of the event.
	Identity() string
	//Set a unique ID.
	SetIdentity(identity string)
}

DomainEvent Interface definition of domain events for subscription and publishing of entities. To create a domain event, you must implement the interface's methods.

type Entity

type Entity interface {
	//The unique ID of the entity.
	Identity() string
	//Returns the requested Worer
	Worker() Worker
	Marshal() ([]byte, error)
	//Add a publishing event.
	AddPubEvent(DomainEvent)
	//Get all publishing events..
	GetPubEvents() []DomainEvent
	//Delete all publishing events.
	RemoveAllPubEvent()
	//Add a subscription event.
	AddSubEvent(DomainEvent)
	//Get all subscription events..
	GetSubEvents() []DomainEvent
	//Delete all subscription events.
	RemoveAllSubEvent()
}

Entity is the entity's father interface.

type Infra

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

Infra . The parent class of the infrastructure, which can be inherited using the parent class's methods.

func (*Infra) BeginRequest

func (infra *Infra) BeginRequest(rt Worker)

BeginRequest Polymorphic method, subclasses can override overrides overrides. The request is triggered after entry.

func (*Infra) FetchCustom added in v1.8.9

func (infra *Infra) FetchCustom(obj interface{})

FetchCustom gets the installed custom data sources.

func (*Infra) FetchOnlyDB added in v1.8.9

func (infra *Infra) FetchOnlyDB(db interface{}) error

FetchOnlyDB Gets the installed database handle.

func (*Infra) FetchSingleInfra added in v1.8.9

func (infra *Infra) FetchSingleInfra(com interface{}) bool

FetchSingleInfra Gets the single-case component.

func (*Infra) InjectBaseEntity added in v1.7.5

func (infra *Infra) InjectBaseEntity(entity Entity)

InjectBaseEntity The base class object that is injected into the entity.

func (*Infra) InjectBaseEntitys added in v1.7.5

func (infra *Infra) InjectBaseEntitys(entitys interface{})

InjectBaseEntitys The base class object that is injected into the entity.

func (*Infra) NewH2CRequest

func (infra *Infra) NewH2CRequest(url string, transferBus ...bool) requests.Request

NewH2CRequest transferBus : Whether to pass the context, turned on by default. Typically used for tracking internal services.

func (*Infra) NewHTTPRequest added in v1.8.0

func (infra *Infra) NewHTTPRequest(url string, transferBus ...bool) requests.Request

NewHTTPRequest transferBus : Whether to pass the context, turned on by default. Typically used for tracking internal services.

func (*Infra) Redis

func (infra *Infra) Redis() redis.Cmdable

Redis Gets the installed redis client.

func (*Infra) Worker

func (infra *Infra) Worker() Worker

Worker Returns the requested Worer.

type Initiator

type Initiator interface {
	// Accepts a string with the route path, and one or more IrisHandler.
	// CreateParty Makes a new path by concatenating the application-level router's
	// prefix and the specified route path, creates an IrisRouter with the new path
	// and the those specified IrisHandler, and returns the IrisRouter.
	CreateParty(relativePath string, handlers ...context.Handler) iris.Party
	// Accepts a string with the route path, an IrisController, and
	// one or more IrisHandler. BindController resolves the application's dependencies,
	// and creates an IrisRouter and an IrisMVCApplication. the IrisMVCApplication
	// would be attached on IrisRouter and the EventBus after it has created.
	BindController(relativePath string, controller interface{}, handlers ...context.Handler)
	// Accepts an IrisRouter and an IrisController.
	// BindControllerWithParty Resolves the application's dependencies, and creates
	// an IrisRouter and an IrisMVCApplication. the IrisMVCApplication would be attached
	// on IrisRouter and the EventBus after it has created.
	BindControllerWithParty(party iris.Party, controller interface{})
	// Bind a function that creates the service.
	BindService(f interface{})
	// Adds a Dependency for iris controller.
	// Because of ambiguous naming, I've been create InjectIntoController as an
	// alternative. Considering remove this function in the future.
	InjectController(f interface{})
	// Bind a function that creates the repository.
	BindRepository(f interface{})
	// Bind a function that creates the repository.
	BindFactory(f interface{})

	// Accepts an IrisContext and a pointer to the typed service. GetService
	// looks up a service from the ServicePool by the type of the pointer and fill
	// the pointer with the service.
	GetService(ctx iris.Context, service interface{})
	// Accepts an IrisContext and a pointer to the typed service. FetchService
	// looks up a service from the ServicePool by the type of the pointer and fill
	// the pointer with the service.
	FetchService(ctx iris.Context, service interface{})
	// Bind a function that creates the repository infrastructure.
	BindInfra(single bool, com interface{})
	// Accepts an IrisContext and a pointer to the typed service. GetInfra
	// looks up a service from the InfraPool by the type of the pointer and fill the
	// pointer with the service.
	GetInfra(ctx iris.Context, com interface{})
	// Accepts an IrisContext and a pointer to the typed service. GetInfra
	// looks up a service from the InfraPool by the type of the pointer and fill the
	// pointer with the service.
	FetchInfra(ctx iris.Context, com interface{})
	// You need to listen for message events using http agents.
	// eventName is the name of the event.
	// objectMethod is the controller that needs to be received.
	// appointInfra can delegate infrastructure.
	ListenEvent(eventName string, objectMethod string, appointInfra ...interface{})
	// Adds a builder function which builds a BootManager.
	BindBooting(f func(bootManager BootManager))
	// Go back to the iris app.
	Iris() *iris.Application
}

Initiator Initialize the binding relationship between the user's code and the associated code.

type IrisApplication added in v1.8.8

type IrisApplication = iris.Application

IrisApplication is a type alias to iris.Application

type IrisConfiguration added in v1.8.8

type IrisConfiguration = iris.Configuration

IrisConfiguration is a type alias to iris.Configuration.

type IrisContext added in v1.8.8

type IrisContext = iris.Context

IrisContext is a type alias to iris.Context

type IrisController added in v1.8.8

type IrisController = interface{}

IrisController represents a standard iris controller.

type IrisHandler added in v1.8.8

type IrisHandler = context.Handler

IrisHandler is a type alias to context.Handler.

type IrisHostConfigurator added in v1.8.8

type IrisHostConfigurator = host.Configurator

IrisHostConfigurator is a type alias to host.Configurator

type IrisMVCApplication added in v1.8.8

type IrisMVCApplication = mvc.Application

IrisMVCApplication is a type alias to mvc.Application.

type IrisParty added in v1.8.8

type IrisParty = iris.Party

IrisParty is a type alias to iris.Party.

type IrisRunner added in v1.8.8

type IrisRunner = iris.Runner

IrisRunner is a type alias to iris.Runner

type JMap

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

JMap .

func NewJMap

func NewJMap(openLock ...bool) *JMap

NewJMap .

func (*JMap) AllKey

func (jm *JMap) AllKey() []interface{}

AllKey .

func (*JMap) DelAll

func (jm *JMap) DelAll()

DelAll .

func (*JMap) Exist

func (jm *JMap) Exist(key interface{}) bool

Exist .

func (*JMap) Get

func (jm *JMap) Get(key interface{}, value interface{}) error

Get .

func (*JMap) Interface

func (jm *JMap) Interface(key interface{}) interface{}

Interface .

func (*JMap) Remove

func (jm *JMap) Remove(key interface{})

Remove .

func (*JMap) Set

func (jm *JMap) Set(key interface{}, value interface{})

Set .

func (*JMap) SetOrStore

func (jm *JMap) SetOrStore(key interface{}, value interface{}) (v interface{}, set bool)

SetOrStore .

type Logger

type Logger interface {
	Print(v ...interface{})
	Println(v ...interface{})
	Fatal(v ...interface{})
	Fatalf(format string, args ...interface{})
	Error(v ...interface{})
	Errorf(format string, args ...interface{})
	Warn(v ...interface{})
	Warnf(format string, args ...interface{})
	Info(v ...interface{})
	Infof(format string, args ...interface{})
	Debug(v ...interface{})
	Debugf(format string, args ...interface{})
}

Logger The interface definition of the log.

type Prometheus

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

Prometheus is a handler that exposes prometheus metrics for the number of requests, the latency and the response size, partitioned by status code, method and HTTP path.

Usage: pass its `ServeHTTP` to a route or globally.

func (*Prometheus) OrmWithLabelValues

func (p *Prometheus) OrmWithLabelValues(model, method string, e error, starTime time.Time)

OrmWithLabelValues .

func (*Prometheus) RegisterCounter

func (p *Prometheus) RegisterCounter(conter *prometheus.CounterVec)

RegisterCounter .

func (*Prometheus) RegisterHistogram

func (p *Prometheus) RegisterHistogram(histogram *prometheus.HistogramVec)

RegisterHistogram .

type Repository

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

Repository . The parent class of the repository, which can be inherited using the parent class's methods.

func (*Repository) BeginRequest

func (repo *Repository) BeginRequest(rt Worker)

BeginRequest Polymorphic method, subclasses can override overrides overrides. The request is triggered after entry.

func (*Repository) FetchCustom added in v1.8.9

func (repo *Repository) FetchCustom(obj interface{})

FetchCustom Gets the installed custom data sources.

func (*Repository) FetchDB added in v1.7.13

func (repo *Repository) FetchDB(db interface{}) error

FetchDB Gets the installed database handle. DB can be changed through AOP, such as transaction processing.

func (*Repository) FetchOnlyDB added in v1.8.9

func (repo *Repository) FetchOnlyDB(db interface{}) error

FetchOnlyDB Gets the installed database handle.

func (*Repository) InjectBaseEntity

func (repo *Repository) InjectBaseEntity(entity Entity)

InjectBaseEntity The base class object that is injected into the entity.

func (*Repository) InjectBaseEntitys

func (repo *Repository) InjectBaseEntitys(entitys interface{})

InjectBaseEntitys The base class object that is injected into the entity.

func (*Repository) NewH2CRequest

func (repo *Repository) NewH2CRequest(url string, transferBus ...bool) requests.Request

NewH2CRequest transferBus : Whether to pass the context, turned on by default. Typically used for tracking internal services.

func (*Repository) NewHTTPRequest added in v1.8.0

func (repo *Repository) NewHTTPRequest(url string, transferBus ...bool) requests.Request

NewHTTPRequest transferBus : Whether to pass the context, turned on by default. Typically used for tracking internal services.

func (*Repository) Redis

func (repo *Repository) Redis() redis.Cmdable

Redis Gets the installed redis client.

func (*Repository) Worker

func (repo *Repository) Worker() Worker

Worker Returns the requested Worer.

type Scanner

type Scanner interface {
	Scan(src interface{}) error
}

Scanner .

type ServiceLocatorImpl added in v1.8.8

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

ServiceLocatorImpl The implementation of service positioning.

func (*ServiceLocatorImpl) Call added in v1.8.8

func (locator *ServiceLocatorImpl) Call(fun interface{}) error

Call Called with a service locator.

func (*ServiceLocatorImpl) InstallBeginCallBack added in v1.8.8

func (locator *ServiceLocatorImpl) InstallBeginCallBack(f func(Worker))

InstallBeginCallBack Install the callback function that started. Triggered before the callback function.

func (*ServiceLocatorImpl) InstallEndCallBack added in v1.8.8

func (locator *ServiceLocatorImpl) InstallEndCallBack(f func(Worker))

InstallEndCallBack The callback function at the end of the installation. Triggered after the callback function.

type UnitTest

type UnitTest interface {
	FetchService(service interface{})
	FetchRepository(repository interface{})
	FetchFactory(factory interface{})
	InstallDB(f func() (db interface{}))
	InstallRedis(f func() (client redis.Cmdable))
	InstallCustom(f func() interface{})
	Run()
	SetRequest(request *http.Request)
	InjectBaseEntity(entity interface{})
}

UnitTest Unit testing tools.

func NewUnitTest added in v1.8.8

func NewUnitTest() UnitTest

NewUnitTest .

type UnitTestImpl

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

UnitTestImpl Unit testing tools.

func (*UnitTestImpl) FetchFactory added in v1.8.9

func (u *UnitTestImpl) FetchFactory(factory interface{})

FetchFactory .

func (*UnitTestImpl) FetchRepository added in v1.8.9

func (u *UnitTestImpl) FetchRepository(repository interface{})

FetchRepository .

func (*UnitTestImpl) FetchService added in v1.8.9

func (u *UnitTestImpl) FetchService(service interface{})

FetchService .

func (*UnitTestImpl) InjectBaseEntity

func (u *UnitTestImpl) InjectBaseEntity(entity interface{})

InjectBaseEntity .

func (*UnitTestImpl) InstallCustom added in v1.9.0

func (u *UnitTestImpl) InstallCustom(f func() interface{})

InstallCustom .

func (*UnitTestImpl) InstallDB added in v1.7.13

func (u *UnitTestImpl) InstallDB(f func() (db interface{}))

InstallDB .

func (*UnitTestImpl) InstallRedis

func (u *UnitTestImpl) InstallRedis(f func() (client redis.Cmdable))

InstallRedis .

func (*UnitTestImpl) Run

func (u *UnitTestImpl) Run()

Run .

func (*UnitTestImpl) SetRequest

func (u *UnitTestImpl) SetRequest(request *http.Request)

SetRequest .

type Worker

type Worker interface {

	// Point to current iris.Context.
	IrisContext() iris.Context

	// Returns current Logger.
	Logger() Logger

	// Set current Logger instead Logger.
	SetLogger(Logger)

	// Store Returns an address to current memstore.Store.
	//
	// memstore.Store is a collection of key/value entries. usually use to store metadata produced by freedom runtime.
	Store() *memstore.Store

	// Returns an address to current Bus.
	Bus() *Bus

	// Returns current context.
	Context() stdContext.Context

	// Set current context instead Context.
	WithContext(stdContext.Context)

	// Seturns a time since this Worker be created.
	StartTime() time.Time

	// DeferRecycle marks the resource won't be recycled immediately after
	// the request has ended.
	//
	// It is a bit hard to understand what is, here is a simply explain about
	// this.
	//
	// When an HTTP request is incoming, the program will probably serve a bunch
	// of business logic services, DB connections, transactions, Redis caches,
	// and so on. Once those procedures has done, the system should write
	// response and release those resource immediately. In other words, the
	// system should do some clean up procedures for this request. You might
	// thought it is a matter of course. But in special cases, such as goroutine
	// without synchronizing-signal. When all business procedures has completed
	// on business goroutine, and prepare to respond. GC system may be run before
	// the http handler goroutine to respond to the client. Once this opportunity
	// was met, the client will got an "Internal Server Error" or other wrong
	// result, because resource has been recycled by GC before to respond to client.
	DeferRecycle()

	// Indicates system need to wait a while for recycle resource.
	IsDeferRecycle() bool

	// Returns a rand.Rand act a random number seeder.
	Rand() *rand.Rand
}

Worker Describes a global context which use to share the internal component (i.e infrastructure, transaction, logger and so on) with middleware, controller, domain service and etc.

Jump to

Keyboard shortcuts

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