Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
config Initial commit Aug 1, 2018
docker Add a docker compose file for mongo Aug 2, 2018
Dockerfile
LICENSE
README.md
default_env.sh
go.mod
go.sum
main.go

README.md

di-example

REST API to manage a list of car stored in mongodb.

It shows how to use sarulabs/di in a web application.

More explanations can be found in this post:

Routes

Method URL Role JSON Body example
GET /cars List cars
POST /cars Insert car {"brand": "audi", "color": "black"}
GET /cars/{id} Get car
PUT /cars/{id} Update car {"brand": "audi", "color": "black"}
DELETE /cars/{id} Delete car

Dependencies and vgo

The dependencies are handled with vgo. You need to install vgo first:

go get -u golang.org/x/vgo

Then you can use vgo run main.go to start the application.

Environment

You need to set some environment variables before running this application:

  • SERVER_PORT: the port for the rest api (eg: 8080)
  • MONGO_URL: the mongodb address (eg: 127.0.0.1:27017)

To use the default values you can use the default_env.sh script:

source default_env.sh
vgo run main.go

Run with docker

It is also possible to run this application with docker compose:

docker-compose -f docker/compose.yml up --build

Or if you only want to run mongo in docker and not the rest api:

docker-compose -f docker/mongo.yml up
You can’t perform that action at this time.