Case
Sending email
Folder Structure
- cmd/sender/main.go
- internal/services/sender/sender.go
- adapters/gmail/gmail.go
- adapters/hotmail/hotmail.go
Steps
Create port
File: internal/services/sender/sender.go

- 
IEmailPortwill be interface for adapter
Create core business
File: internal/services/sender/sender.go

- 
IEmailServicewill be interface for UberFX
- 
EmailServicewill be struct of service with attribute emailPort(will be injected by UberFX)
- 
NewEmailServiceis constructor
Create adapters
- 
GmailAdapterwill be interface for UberFX
File: adapters/hotmail/hotmail.go
** Hotmail like gmail, just replace gmail with hotmail **
Create program
- 
NewEmailAdapterfunction will let UberFX know thatIEmailPortinterface will use Gmail adapter struct
- We can switch adapter to hotmail by comment out return hotmail.NewHotmailAdapter()in functionNewEmailAdapter
 



 
    
Top comments (0)