Useless, (almost) production-ready demo web application.
Features:
- Rest API to create, find and delete vehicles
- Persistent storage in database
- 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
- Github actions, see .github/workflows/go.yml
- Docker image generation, see Dockerfile
- Database migrations
- Authentication/session
- i18n
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
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 :)
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'
$ docker exec -it hello-scylla nodetool status
$ docker exec -it hello-scylla cqlsh
cqlsh> SELECT * from hello.vehicles;