This a Golang project to start take a screenshot form URLS using pdfcrowd API and save the images data to mysql database before start to explain this porject please
- 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 of all let me speak about the solution architecture, the used is clean architecture with dependency injection.
This architecture has 4 layers
- models
- imagehandler
- middleware
- imagehttphandler
Model layer is reposable to create a structs for our models the to be transfered to the database or bind the requet into it.
This contains the repositoris as well as the business logig, this divided into two folders, one called usecase that will handle all the busines logic, and the last one is called repository to handle the database operation
This is to handle the crossorigin on the http request
This is responsable to create the http request, this would take the a list of URLS then start to screenshot the urls and the image to the folder path, that would be add 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 this is provide a high performance, extensible, minimalist for a go web framework/p>
for more information please check this url : https://echo.labstack.com/
This helo to read the value form the configuration file for more info please check this url : https://github.com/spf13/viper
This API will help us to take the URL and convert it to imagem and unfortunately this is not free I am using a trial
After the screen have been taken, I moved it to a shared path folder with a UUID to create a unique name for the screenshot image, and then the Image data will be saved to the database, such as folder path and the creation time to the database.