Centralized email automation service for hasCorp.
A complete example:
go run cmd/mailservice/main.go -bypass -port=2564
Store your SendGrid API key in a credentials.json at the root of the repo
(this is in the .gitignore). Take a look at ./credentials.json.template
as an example:
{
"SENDGRID_API_KEY": "Your API key goes here",
"FROM_NAME": "Friendly Name",
"FROM_ADDR": "some-email@fake.dev"
}If you don't want to store the credentials and configurations in a JSON file in the project repo, you can expose environment variables with the same key names.
# for Linux/Unix systems
export SENDGRID_API_KEY="Your API key goes here",
export FROM_NAME="Friendly Name",
export FROM_ADDR="some-email@fake.dev"# for Windows systems
set SENDGRID_API_KEY="Your API key goes here",
set FROM_NAME="Friendly Name",
set FROM_ADDR="some-email@fake.dev"For local development, it makes sense to do some testing without requiring
a hard dependency on the authentication service to verify incoming requests.
When running locally, pass in the -bypass flag to ignore client auth verification
go run cmd/mailservice/main.go -bypass
For local development, you can configure a static token to verify
that the header is read correctly for auth protected routes. Set a
static token with the token flag. Note that the -bypass flag takes
precedence over this.
go run cmd/mailservice/main.go -token abc123
curl -d '{"foo": "bar"}' -H 'Authorization: abc123' -H 'Content-Type: application/json' localhost:8000/mail/fooBy default, the HTTP server listens on port 8000. This can be changed when
running via the -port flag:
go run cmd/mailservice/main.go -bypass -port=2564
You can build the project locally simply by running:
go build .Or you can use the Dockerfile at the root of the repo to build an image.
docker build -t hascorp/hasmail -f Dockerfile .You can run the project locally with go:
go run ./cmd/mailserviceOr you can use the built Docker image to run a container:
docker run -it -p 8000:8000 hascorp/hasmailPing the server with cURL or your preferred client:
# ping healthcheck endpoint
curl localhost:8000/
# verify routes work with no-op endpoint
curl -d '{"a": "b"}' -H 'Content-Type: application/json' localhost:8000/mail/noop
# send a real sample mail end-to-end
curl -d '{"name": "Hank Pecker", "vars": {"foo": "bar"}, "recipient": "hank@hascorp.dev"}' -H 'Content-Type: application/json' localhost:8000/mail/sampleTODO: this
Build with the production Dockerfile:
docker build -t hascorp/hasmail-prod -f Dockerfile.production .This can be tested locally like the regular Dockerfile:
docker run -it -p 8000:8000 hascorp/hasmail-prodRun unit tests locally:
go test -v ./...TBD
TBD
Install golangci-lint: https://golangci-lint.run/usage/install/#local-installation
Run it:
golangci-lint run