An open API service indexing awesome lists of open source software.

https://github.com/arpitsingh134/go-data-ingestor

It fetches log data from a public API, applies transformation, and stores it in a MongoDB database running inside a Docker container.
https://github.com/arpitsingh134/go-data-ingestor

docker git go mongodb mongoexpress

Last synced: 2 months ago
JSON representation

It fetches log data from a public API, applies transformation, and stores it in a MongoDB database running inside a Docker container.

Awesome Lists containing this project

README

          

# Go Data Ingestion Service

It fetches log data from a public API, applies transformation, and stores it in a **MongoDB** database running inside a Docker container.

It also includes:
- Dockerized setup
- Unit testing
- Mongo Express UI for easy database inspection
- MongoDB shell access via Docker

---

## ๐Ÿš€ Getting Started

### ๐Ÿ”ง Prerequisites

* [Git](https://git-scm.com/)
* [Docker](https://www.docker.com/)
* [Docker Compose](https://docs.docker.com/compose/)

### ๐Ÿงช Run the Application

```bash
git clone https://github.com/your-username/go-data-ingestor.git
cd go-data-ingestor
docker-compose up --build
```

---

## โœ… Run Tests

```bash
go test ./test/...
```

---

## ๐Ÿ—„๏ธ MongoDB Details

* MongoDB URI: `mongodb://localhost:27017`
* Database: `logdb`
* Collection: `posts`

---

## ๐Ÿ“Š Viewing Ingested Data

### ๐Ÿ”น Option 1: Using Mongo Express (Browser UI)

1. Run the app using Docker Compose:

```bash
docker-compose up --build
```

2. Open your browser:

```
http://localhost:8081
```

3. Youโ€™ll see the Mongo Express dashboard.

4. Navigate to:

* Database: `logdb`
* Collection: `posts`

5. Click to view the ingested JSON documents.

---

### ๐Ÿ”น Option 2: Using Mongo Shell in Docker

1. Open terminal access to MongoDB:

```bash
docker exec -it go-data-ingestor-mongo mongosh
```

2. Switch to your database:

```js
use logdb
```

3. View documents:

```js
db.posts.find().pretty()
```

---

## ๐Ÿ” API Endpoint Used

* Source: [`https://jsonplaceholder.typicode.com/posts`](https://jsonplaceholder.typicode.com/posts)

---

## ๐Ÿ”„ Transformation Logic

Each record from the API is transformed to include:

* `ingested_at`: UTC timestamp at time of ingestion
* `source`: `"placeholder_api"`

---

## ๐Ÿงช Trade-offs & Improvements

* Focused on local-first
* Could extend to cloud-native storage (e.g., AWS S3 or DynamoDB)
* Additional observability and retry logic could be added
* Uses simple MongoDB schema for flexibility and fast prototyping

---

## ๐Ÿงฑ Project Structure

```bash
.
โ”œโ”€โ”€ cmd/
โ”‚ โ””โ”€โ”€ main.go # Entry point
โ”œโ”€โ”€ config/
โ”‚ โ””โ”€โ”€ config.go # MongoDB and app config
โ”œโ”€โ”€ internal/
โ”‚ โ”œโ”€โ”€ fetcher/ # API fetching logic
โ”‚ โ”œโ”€โ”€ transformer/ # Data transformation
โ”‚ โ”œโ”€โ”€ repository/ # MongoDB interaction
โ”‚ โ””โ”€โ”€ models/ # Data model definitions
โ”œโ”€โ”€ test/ # Unit tests
โ”œโ”€โ”€ go.mod
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ docker-compose.yml
โ””โ”€โ”€ README.md
````

---