response.go 495 B

1234567891011121314151617181920212223242526
  1. package middleware
  2. //IMiddleware handler
  3. type IMiddleware interface {
  4. Process(data interface{})
  5. }
  6. //ResponseRender .
  7. type ResponseRender func(data interface{}, err error)
  8. //Response response handler
  9. func Response(data interface{}, err error, r ResponseRender, i IMiddleware) {
  10. if data != nil && i != nil {
  11. i.Process(data)
  12. }
  13. if r != nil {
  14. r(data, err)
  15. }
  16. }
  17. //Request request handler
  18. func Request(data interface{}, i IMiddleware) {
  19. if data != nil && i != nil {
  20. i.Process(data)
  21. }
  22. }