# Packages
# README
Screenshot using Golang with clean architecture
This is a Golang project to take screenshots from URLs using the Pdfcrowd API and save the image data to a MySQL database. Before I start explaining this project, please.
install the following packages
- go get github.com/go-sql-driver/mysql
- go get github.com/labstack/echo
- go get -u github.com/spf13/viper
- go get github.com/pdfcrowd/pdfcrowd-go
First, let me talk about the solution architecture. The architecture used is clean architecture with dependency injection.
This architecture has 4 layers
- models
- imagehandler
- middleware
- imagehttphandler
Model layer
The model layer is responsible for creating structs for our models to be transferred to the database or for binding the request to them.
imagehandler
This layer contains the repositories as well as the business logic. It is divided into two folders: one called 'usecase,' which handles all the business logic, and the other called 'repository,' which handles database operations.
middleware
This is to handle the CORS (Cross-Origin Resource Sharing) on the HTTP requests
imagehttphandler
This is responsible for creating the HTTP requests. It takes a list of URLs, then starts to take screenshots of those URLs and save the images to the specified folder path, which will be added to the config.json file.
In this case, I am using three packages.
- go get github.com/labstack/echo
- go get -u github.com/spf13/viper
- go get github.com/pdfcrowd/pdfcrowd-go
Why Echo? Because it provides high performance, extensibility, and a minimalist approach for a Go web framework./p>
For more information, please check this URL: https://echo.labstack.com/.
viber
This helps to read the values from the configuration file. For more information, please check this URL: https://github.com/spf13/viper.
pdfcrowd
This API will help us take a URL and convert it to an image. Unfortunately, this service is not free; I am currently using a trial.
After the screenshot has been taken, I moved it to a shared folder path with a UUID to create a unique name for the image. Then, the image data, including the folder path and creation time, will be saved to the database.