Categorygithub.com/agaber90/gocleanarchitecture
repository
0.0.0-20240926115615-f5e50a1a1bf8
Repository: https://github.com/agaber90/gocleanarchitecture.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# 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


  1. go get github.com/go-sql-driver/mysql
  2. go get github.com/labstack/echo
  3. go get -u github.com/spf13/viper
  4. 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

  1. models
  2. imagehandler
  3. middleware
  4. 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.

  1. go get github.com/labstack/echo
  2. go get -u github.com/spf13/viper
  3. go get github.com/pdfcrowd/pdfcrowd-go
# echo

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.