Skip to content

Sample web application written in Go (with Scylla database)

Notifications You must be signed in to change notification settings

bwalter/golang-scylla

Repository files navigation

golang-scylla

Useless, (almost) production-ready demo web application.

Features:

  • Rest API to create, find and delete vehicles
  • Persistent storage in database

Software Design

Architecture:

architecture image

Libraries/tools:

  • HTTP server (based on net/http), see main.go
  • Basic routing (based on gorilla/mux), see app/app.go
  • Scylla database with gocql driver and gocqlx extension
  • (Basic) OpenAPI generation based on apidoc, see Makefile ('apidoc' target), comments in main.go and app/app.go
  • JSON validation based on validator
  • Command line arguments parsing based on go-flags
  • Unit tests based on testify/require and mockgen, see app/app_test.go and Makefile ('unit-tests' target)
  • Integration test using httptest, see integration_tests/app_integration_test.go and Makefile ('integration-tets' target)
  • Linting based on golangci-lint, see Makefile ('check' target) and .golangci.yaml

Continuous integration:

  • Github actions, see .github/workflows/go.yml
  • Docker image generation, see Dockerfile

TODO:

  • Database migrations
  • Authentication/session
  • i18n

Class diagram:

classdiagram image

Build and run demo app

Manually (pre-condition: Scylla DB already running):

$ make check
$ make
$ ./bin/hello

Via docker:

$ docker run --name hello-scylla -d -p 9042:9042 scylladb/scylla
$ docker build -t hello-app .
$ docker run -t -i -p 3001:3001 --link=hello-scylla:scylla -it hello-app --addr scylla

Via docker-compose:

$ docker-compose build
$ docker-compose up

Tests

All tests:

$ make test

Unit tests only:

$ make unit-tests

Integration tests:

$ make integration-tests

If it still crashes even after testing: try the Rust version :)

Test Rest API

Create vehicles:

$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3001/vehicle -d '{"vin":"vin1","engine":"Combustion"}'
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3001/vehicle -d '{"vin":"vin2","engine":"Ev", ev_data: {"battery_capacity_in_kwh": 62, "soc_in_percent": 74}}
$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3001/vehicle -d '{"vin":"vin3","engine":"Phev"}}'

Find vehicle by vin:

$ curl -v -H "Accept: application/json" -H "Content-type: application/json" localhost:3001/vehicle -G --data-urlencode 'vin=vin2'

Check database

$ docker exec -it hello-scylla nodetool status
$ docker exec -it hello-scylla cqlsh
cqlsh> SELECT * from hello.vehicles;

About

Sample web application written in Go (with Scylla database)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published