hlhendy / emails

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Client Structure

.
├── README.md
├── handlers.go
├── internal
│   ├── messages
│   │   ├── mailgun.go
│   │   ├── mandrill.go
│   │   ├── messages.go
│   │   └── messages_test.go
│   └── testclient
│       └── testclient.go
├── main.go
├── models
│   └── models.go
└── settings.json

Tradeoffs

There are many things I would do differently given more time. First, I didn't really have time to write good tests. I would add in unit tests for each function. I would take advantage of the Message interface to mock out responses from the email providers. I included one very basic example of how I might structure a test, but it's not complete in that it doesn't test all functionality.

I would also:

  • add auth to the endpoint, as well as encrypt the api_key vs having it in plain text in the settings file.

  • use the from and to names

  • add more validation to the html being passed in.

  • implement a second email provider (it looks like Mandrill is no longer free; Mailchip would not allow me to create an api key with my free account).

  • genericize the NewRequest function.

How to Install & Run

  1. Install go (this may vary by package manager) ex. brew install go

  2. Create go workspace

  • mkdir ~/go
  • cd ~/go && mkdir src
  • cd ~/go/src && mkdir github.com
  1. Clone into go path cd ~/go/src/github.com && git clone git@github.com:hlhendy/emails.git

  2. Add API Key to settings.json file

  3. Start server cd ~/go/src/github.com/emails && go build && ./emails

  4. Curl

curl -XPOST localhost:8080/email -d '{"to":"<to>", "from":"<from>", "to_name":"<to-name>", "from_name":"<from-name>", "subject":"It's a test subject!", "body":"<body>"}' -H "Content-Type: application/json"
  1. Run Tests cd ~/go/emails && go test ./...

About


Languages

Language:Go 100.0%