Documentation ¶
Index ¶
- Variables
- type Grelay
- type GrelayChecker
- type GrelayConfig
- func (c GrelayConfig) WithGo() GrelayConfig
- func (c GrelayConfig) WithGrelayService(service GrelayChecker) GrelayConfig
- func (c GrelayConfig) WithRetryTimePeriod(t time.Duration) GrelayConfig
- func (c GrelayConfig) WithServiceThreshould(ts int64) GrelayConfig
- func (c GrelayConfig) WithServiceTimeout(t time.Duration) GrelayConfig
- type GrelayRequest
- type GrelayService
Constants ¶
This section is empty.
Variables ¶
var ErrGrelayAllRequestsOpened = errors.New("gRelay error - all requests are opened")
ErrGrelayAllRequestsOpened indicates that all services enqueued are open
var ErrGrelayServiceTimedout = errors.New("gRelay error - service timed out")
ErrGrelayServiceTimedout indicates that the service timed out
var ErrGrelayStateOpened = errors.New("gRelay error - state is opened")
ErrGrelayStateOpened indicates that the service has open states
Functions ¶
This section is empty.
Types ¶
type Grelay ¶
type Grelay interface { /* CreateRequest is responsable to create a GrelayRequest to enqueue new functions later. EX: gr := grelay.CreateRequest() */ CreateRequest() GrelayRequest }
Grelay is an interface that have Enqueue function
func NewGrelay ¶
func NewGrelay(m map[string]GrelayService) Grelay
NewGrelay creates a grelay config using a map of string:GrelayService
EX:
config1 := grelay.NewGrelayConfig() service1 := grelay.NewGrelayService(config1) config2 := grelay.NewGrelayConfig() service2 := grelay.NewGrelayService(config2) m := map[string]GrelayService{ "service1": service1, "service2": service2, } g := NewGrelay(m)
type GrelayChecker ¶
type GrelayChecker interface {
Ping() error
}
GrelayChecker has a ping function that is responsible for ping to the server when the state is OPEN
type GrelayConfig ¶
type GrelayConfig struct {
// contains filtered or unexported fields
}
GrelayConfig is a structure for GrelayService configuration
func NewGrelayConfig ¶
func NewGrelayConfig() GrelayConfig
NewGrelayConfig create config for grelay with these values:
- RetryTimePeriod: 10s
- ServiveTimeout: 10s
- ServiceThreshould: 10 times
func (GrelayConfig) WithGo ¶ added in v0.1.0
func (c GrelayConfig) WithGo() GrelayConfig
WithGo is responsible to execute in a goroutine your call function. If get ServiceTimeout, grelay will return instead of hold your call.
func (GrelayConfig) WithGrelayService ¶
func (c GrelayConfig) WithGrelayService(service GrelayChecker) GrelayConfig
WithGrelayService sets the service that is responsible for ping to the server when the state is OPEN
func (GrelayConfig) WithRetryTimePeriod ¶
func (c GrelayConfig) WithRetryTimePeriod(t time.Duration) GrelayConfig
WithRetryTimePeriod sets the retry time period when the state is OPEN.
ATTENTION: Do not put a really short time (EX: 1 microsecond) to not lock a lot your application
func (GrelayConfig) WithServiceThreshould ¶
func (c GrelayConfig) WithServiceThreshould(ts int64) GrelayConfig
WithServiceThreshould sets the limit of threshould to change the state to OPEN
func (GrelayConfig) WithServiceTimeout ¶
func (c GrelayConfig) WithServiceTimeout(t time.Duration) GrelayConfig
WithServiceTimeout sets the limit of time that the service can take to increase the threashould
type GrelayRequest ¶
type GrelayRequest interface { /* Enqueue is responsable to enqueue functions from a specific service in GrelayRequest EX: gr := grelayRequest.Enqueue("mygrelayservice", func() (interface{}, error) { value, err := myservice.GET("userID") if err != nil { return nil, err } return value, err }) */ Enqueue(string, func() (interface{}, error)) GrelayRequest /* Exec is responsable to execute requests from GrelayRequest queue. EX: gr := grelayRequest.Enqueue("mygrelayservice", func() (interface{}, error) { // make request1 }) gr = grelayRequest.Enqueue("mygrelayservice2", func() (interface{}, error) { // make request2 }) val, err := gr.Exec() */ Exec() (interface{}, error) }
GrelayRequest is an interface responsable to Enqueue and Exec requests
type GrelayService ¶
type GrelayService interface {
// contains filtered or unexported methods
}
func NewGrelayService ¶
func NewGrelayService(c GrelayConfig) GrelayService