Study project using Golang + fasthttp + MongoDB driver.
recipes-api is an rest api to store receipt links along with some notes.
The purpouse is to keep Golang codding skills and improve and/or test some concepts.
You can run recipes-api using 3 differents way. The following steps will guide you through the 3 ways to run it :)
You can run this api project navigating to cmd folder and running build and run. When executing run command you can pass a third argument as dev, qa or prod indicating the environment you want to execute. When no arg is passing it will assume dev.
cd cmd
go build
go run main.go
go run main.go [dev, qa, prod]
You can check the environment configurations on fodler configs/files/mongodb and configs/files/server by its indication on config.mongodb..json. Exampels:
- config.mongodb.dev.json
- config.server.dev.json
The second way to run this app is by running manually all the steps using docker files to get it up and runnign.
First, you should Create a docker image from this project by running
docker build -t recipes-api .
then pull mongodb
docker pull mongo:latest
Now we should have a volume
docker volume create --name=mongodata
Run MongoDb on detached mode using the volume with the name mongodb
docker run --name mongodb -v mongodata:/data/db -p 27017:27017-d mongo
Once we get it up lets run the app using name as dev-recipes-api passing the mongodb connection as parameter using port 8087 and run it on detached mode.
`` docker run -d --name dev-recipes-api -e MONGO_URL=mongodb://172.17.0.2:27017/?readPreference=primary&appname=MongoDB%20Compass%20Community&ssl=false -p 8087:8061 recipes-api
``
This is my fav :)
the run-dev.ps1 file on root folder contains all the steps needed to put recipes-api up and running.
So, you cann run it by simply executing:
.\run-dev.ps1
Now you know all the ways to put it running, just try :)
Check the API status calling the api :
localhost:/ping
This project is organized in 3 layers.
- Controller (api)
contains API level executions, such as capturing parameters, parsing body to models and responsing api executions setting http status and messages.
- Use Case
Executes the business rules, such as validations.
- Repository
Execute commands on MongoDB
-
api : Register controllers
-
cmd : Main application
-
configs : Configuration files and procedures
-
handlers : Prepare Server
-
internals : Business side information
-
_documentation : support for readme files
- Adding GRPC
- For a log project