Skip to content

jdelobel/go-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-api

Description

This project is based on https://github.com/ardanlabs/gotraining/blob/master/starter-kits/http. It uses postgresql to persist data.

Install dependencies

$ go get ./...

Launch Docker containers (postgres)

You have to launch docker-compose in order to have all the required components up and running:

$ docker-compose up -d

Build and run

$ go build ./cmd/apid
$ ./apid

Database migrations

Migration use cli tool migrate.

Cli installation

$ go get -u -d github.com/mattes/migrate/cli github.com/lib/pq
$ go build -tags 'postgres' -o /usr/local/bin/migrate github.com/mattes/migrate/cli

Example

Create sql migrations files

$ migrate -database "postgres://go-api-postgres:go-api-postgres@localhost:5432/go-api-postgres?x-migrations-table=migrations" create -ext sql -dir migrations create_images

Exec migrations

$ migrate -source=file://migrations -database "postgres://go-api-postgres:go-api-postgres@localhost:5432/go-api-postgres?sslmode=disable" up

Rollback migrations

$ migrate -source=file://migrations -database "postgres://go-api-postgres:go-api-postgres@localhost:5432/go-api-postgres?sslmode=disable" down

Swagger API documentation

You can access to the swagger API documentation at: http://[HOST][PORT]:3000/swagger/api-docs/

Build Docker image from source

$ compile=CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo ./cmd/apid/
$ docker build -t go-api .

Run Docker image

$ docker run --name go-api -e CONFIGOR_APPHOST=0.0.0.0 -e CONFIGOR_DATABASE_HOST=go-api-postgres --link go-api-postgres:go-api-postgres -p 3000:3000 -d go-api

TODO

  • Migrations
  • Logger (Graylog)
  • Make tests
  • Config (configor)
  • Swagger docs
  • Use sqlx instead of sql (structScan)
  • Health and readiness
  • Prometheus metrics
  • Communicate with RabbitMQ
  • Dockerfile (and docker-compose)
  • Jenkins integration
  • govendor (production needs)

Thanks to contribute to this project. Each TODO must be done in a pull request.