Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. // We would make a seaprate {service}/data package. The reason to separate out the data module is to utilize
  2. // private methods to not expose lower-level resources
  3.  
  4. // We would no longer need the big global Databinder and instead replace it with a smaller Binder for each resource
  5. // The benifit of switching off of the interface is we can then leverage private attributes like the clients
  6.  
  7. // The Binders can expose sqlx components like tx in private functions
  8. // The binder methods would be raw management of the resources with no side-effects (i.e. creating a guest
  9. // would not create a guest token)
  10. type GuestBinder struct {
  11. Get func() error
  12. Update func() error
  13. Insert func() error
  14. db *DB
  15. identity *identity.Client
  16. }
  17.  
  18. func NewGuestBinder(identity identity.Client) *GuestBinder {}
  19. func NewGuestBinderMock() *GuestBinder {}
  20.  
  21. type TokenBinder struct {
  22. Get func() error
  23. Update func() error
  24. Insert func() error
  25. updateBatch func(tx *sqlx.Tx) error
  26. db *DB
  27. }
  28.  
  29. func NewTokenBinder(identity identity.Client) *GuestBinder {}
  30. func NewTokenBinderMock() *GuestBinder {}
  31.  
  32. // The you would dependency inject the binders into the processor.
  33. // These can act as processors which can coordinate and utilize private methods accross the different binders
  34. // i.e. CreateGuest would create a guest, token, and ledger entry etc...
  35. type GuestProcessor struct {
  36. Create func() error {}
  37. ActivateGuest func() error {}
  38. guest *GuestBinder
  39. token *TokenBinder
  40. identity *identity.Client
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement