Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kamrulislam/go-docker-mux-redis-notify
It is a REST Go server which uses Redis to save data and also displays the use of a third party email sending using SendGrid. It also provides a docker-compose to build and run all together.
https://github.com/kamrulislam/go-docker-mux-redis-notify
docker docker-compose golang mux redis rest-api sendgrid
Last synced: about 2 months ago
JSON representation
It is a REST Go server which uses Redis to save data and also displays the use of a third party email sending using SendGrid. It also provides a docker-compose to build and run all together.
- Host: GitHub
- URL: https://github.com/kamrulislam/go-docker-mux-redis-notify
- Owner: kamrulislam
- Created: 2019-12-07T05:25:25.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-12-08T21:20:26.000Z (about 5 years ago)
- Last Synced: 2024-04-29T21:22:41.933Z (9 months ago)
- Topics: docker, docker-compose, golang, mux, redis, rest-api, sendgrid
- Language: Go
- Homepage:
- Size: 9.57 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GO Mux Redis Sendgrid Email Docker App
It is a REST Go server which uses Redis to save data and also displays the use of a third party email sending using SendGrid. It also provides a docker-compose to build and run all together.
## Code Structure
The code is best run inside docker containers. To make the process simple, the project includes a `docker-compose.yml` file. It contains two containers `api` and `redis`. Before running the application, the api container needs to be built. A `Dockerfile` is provided to make the build process easy.
All application code sits inside `commands` folder other than docker setup and Go Module files. The project is built using `Go Module` which comes with go version `go1.13`. All necessary build will be handled by the docker setup itself.
## Setup
To build the application please follow the following steps:
- Clone the repository and go inside the cloned repository
```bash
git clone https://github.com/kamrulislam/go-docker-mux-redis-notify.git
cd go-docker-mux-redis-notify
```
- Build the API docker image first using `docker-compose build api` command
- Run the application using `docker-compose up` command
- Wait until you see something like the following from API(`api_1`) and Redis(`cache`)
```bash
cache | 1:M 08 Dec 2019 01:13:07.716 * Ready to accept connections
api_1 | Server listening!
```
- The `api` runs on `8080` port and also maps the same port on host machine.## Checking Process
To create a customer either you can use any API Testing Client (eg., Postman, Talend) or you can use `curl` command in the terminal. Let's see how the functionalities of the application work.
### Create a Customer
- Endpoint: `http://localhost:8080/customer`
- Request: POST
- Body:
```json
{
"Name" : "Kamrul",
"Email" : "[email protected]",
"Phone" : "0400000000"
}
```
- cURL:
```bash
curl 'http://localhost:8080/customer' -H 'Connection: keep-alive' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Sec-Fetch-Site: cross-site' -H 'Sec-Fetch-Mode: cors' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-AU,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' --data-binary $'{\n "Name" : "Kamrul",\n "Email" : "[email protected]",\n "Phone" : "0400000000"\n}' --compressed
```
- Response:
```json
{"Name":"Kamrul","Email":"[email protected]","Phone":"0400000000"}
```### Find a customer by email
- Endpoint: `http://localhost:8080/customer/[email protected]`
- Request: GET- cURL:
```bash
curl 'http://localhost:8080/customer/[email protected]' -H 'Connection: keep-alive' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Sec-Fetch-Site: cross-site' -H 'Sec-Fetch-Mode: cors' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-AU,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' --compressed
```
- Response:
```json
{"Name":"Kamrul","Email":"[email protected]","Phone":"0400000000"}
```### Send notification to a customer identified by email
- Endpoint: `http://localhost:8080/notify/[email protected]`
- Request: GET- cURL:
```bash
curl 'http://localhost:8080/notify/[email protected]' -H 'Connection: keep-alive' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36' -H 'Content-Type: application/json' -H 'Accept: */*' -H 'Sec-Fetch-Site: cross-site' -H 'Sec-Fetch-Mode: cors' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-AU,en-GB;q=0.9,en-US;q=0.8,en;q=0.7' --compressed
```
- Response:
```json
{"success":true}
```## High level design philosophy
- A generic **Router** and **Routes** provided to make the routing process simple for [Mux](http://www.gorillatoolkit.org/pkg/mux)
- A generic Redis controller (`db.go`) added to add (`AddRecord`) and retrieve (`FindRecord`) record
- **Single Responsibility Principle** has been followed. All request handler has there separate files.
- **Notifier** interface has been designed in a way that any concrete implementation of the Notifier would be able to be integrated in easily.
- A concrete implementation (using SendGrid of Twilio) of email notification has also been provided.
## Future improvements- A centralized error handling middleware would be a good idea to add.
- Add some unit tests in another docker-compose.
- Would be good to use Go routine for email sending since it is a blocking call.