Skip to content

A complete Go REST API built with echo, uber/fx and mongodb

Notifications You must be signed in to change notification settings

EclesioMeloJunior/golang-awsome-api

Repository files navigation

Golang Open Food Facts Challenge

This project needs to realize synchronization with Open Food Facts open data and allow CRUD operations with data

Running mongo with docker

To properly execute the application you must have an instance of mongo database running somewhere in your machine. For look we have (docker)[https://docs.docker.com/engine/install/] and (docker compose)[https://docs.docker.com/compose/install/] to help us with the execution of third part apps.

In the root of this project we had a file called docker-compose.yml, inside it contains the definition of three services the first one is the app and; the mongo is the mongo database instance and the mongo-express is a tool to visualize our database data.

To execute the mongo database you must execute:

docker-compose up mongo mongo-express

The above command will start the database at port 27017 and the visualization at http://localhost:8081

Running application

To execute the application you must clone the project inside a folder at your machine then you must create a .env file at the project root, the file .env.example contains the required envs.

The env var CONN_STR should have the format mongodb://root:example@localhost:27017/?authSource=admin The env var DATABASE_NAME should be admin The env var TIME_EXEC_IMPORT should have the format * * * * * (Where the first one represents minutes and the second is the hour) eg. 10 13 * * * = 13h:10m

The other variables represents the email information to be able notify when import fails or succeed

NOTIFY_EMAIL=who_notifies_when_import_job_done@email.com
EMAIL_USER=creds@email.com
EMAIL_PASS=pass
EMAIL_SEVER=smtp.gmail.com //to gmail creds
EMAIL_PORT=587 //gmail smtp

With docker

To run with docker you must have installed (docker)[https://docs.docker.com/engine/install/] and (docker compose)[https://docs.docker.com/compose/install/] and an instance of mongodb must be running (see Running mongo with docker section) and you have filled the .env file. then at the project root run:

docker-compose up app

or if you have make bin installed at your machine you can run:

make docker

Then the application will be running at http://localhost:8080, and documentation at http://localhost:8080/swagger/index.html

Without docker

To run without docker you must have installed the golang (version 1.11+), an instance of mongodb must be running (see Running mongo with docker section) and you have filled the .env file.

After that in the project root you can execute the app runnig:

go run ./main.go

or if you have make bin installed at your machine you can run:

make run

Then the application will be running at http://localhost:8080, and documentation at http://localhost:8080/swagger/index.html

Testing

Ginko and Gomega are the tool used in this projects to create and run test to execute the tests you can type:

go test ./... -v

or

make test

About

A complete Go REST API built with echo, uber/fx and mongodb

Topics

Resources

Stars

Watchers

Forks

Languages