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
-
IEmailPort
will be interface for adapter
Create core business
File: internal/services/sender/sender.go
-
IEmailService
will be interface for UberFX -
EmailService
will be struct of service with attribute emailPort(will be injected by UberFX) -
NewEmailService
is constructor
Create adapters
-
GmailAdapter
will be interface for UberFX
File: adapters/hotmail/hotmail.go
** Hotmail like gmail, just replace gmail with hotmail **
Create program
-
NewEmailAdapter
function will let UberFX know thatIEmailPort
interface will use Gmail adapter struct - We can switch adapter to hotmail by comment out
return hotmail.NewHotmailAdapter()
in functionNewEmailAdapter