forked from easierway/service_decorators
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice_template.go
27 lines (22 loc) · 1.1 KB
/
service_template.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Package service_decorators is to simplify your work on building microservices.
// The common functions for the microservices (such as, Circuit break, Rate limit,
// Metric...) have be encapsulated in the reusable components(decorators).
// To build a service is to decorate the core business logic with the common
// decorators, so you can only focus on the core business logic.
// @Auth [email protected]
// @Created on 2018-6
package service_decorators
// Request is the interface of the service request.
type Request interface{}
// Response is the interface of the service response.
type Response interface{}
// ServiceFunc is the service function definition.
// To leverage the prebuilt decorators, the service function signature should follow it.
type ServiceFunc func(req Request) (Response, error)
// ServiceFallbackFunc is the fallback function definition
type ServiceFallbackFunc func(req Request, err error) (Response, error)
// Decorator is the interface of the decorators.
type Decorator interface {
// Decorate function is to introdoce decorator's the functions
Decorate(ServiceFunc) ServiceFunc
}