Skip to content

Repository files navigation

go-microservice

An educational project for creating a microservice in go

License: Apache2Build Statuscodecov

Running the example

For running the example with the default config (in memory database) you should do :

$ make run

For running the example with PostgreSQL database you should do :

$ make run-postgresql

For running the example with PostgreSQL we require to have it running with the following details :

Server : localhost
Port : 5432
Database : pets
User : petuser
Password : petpwd

To change these details you need to modify the file build/config/postgresql.json

Running the tests

For running the tests you should do :

$ make test

Running the integration tests

For running the integration tests you should do :

$ make integration

These test requires to have Docker running.

Example requests using HTTPie

First install HTTPie

Post a new Pet

$ http POST :8080/pets name=Fluffy race=Dog mod=Happy
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json; charset=utf-8
Date: Sun, 23 Feb 2020 15:31:31 GMT
Location: /pet/1

Query a Pet

$ http :8080/pets/1
HTTP/1.1 200 OK
Content-Length: 52
Content-Type: application/json; charset=utf-8
Date: Sun, 23 Feb 2020 15:32:57 GMT
{
"id": 1,
"mod": "Happy",
"name": "Fluffy",
"race": "Dog"
}

Delete a Pet

$ http DELETE :8080/pets/1
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json; charset=utf-8
Date: Sun, 23 Feb 2020 15:33:42 GMT

Update a Pet

$ http PUT :8080/pets/1 name=Fluffy race=Dog mod=Sad
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/json; charset=utf-8
Date: Sun, 23 Feb 2020 15:31:31 GMT

Get all Pets

$ http GET :8080/pets
HTTP/1.1 200 OK
Content-Length: 104
Content-Type: application/json; charset=utf-8
Date: Mon, 09 Mar 2020 08:07:36 GMT
[
{
"id": 1,
"mod": "Happy",
"name": "Fluffy",
"race": "Dog"
},
{
"id": 2,
"mod": "Brave",
"name": "Lion",
"race": "Cat"
}
]

Health checks

$ http GET :8080/health/readiness
HTTP/1.1 200 OK
Content-Length: 0
Date: Sun, 19 Apr 2020 09:16:38 GMT
$ http :8080/health/liveness
HTTP/1.1 200 OK
Content-Length: 0
Date: Sun, 19 Apr 2020 09:16:45 GMT

Kubernetes deployment

To deploy this service in a local kubernetes:

make deploy

This requires to have a registry running in the same cluster.

When building the docker image you can use the environment variable LOCAL_REGISTRY to point to the docker registry.

About

A educational project for creating a microservice in go

Topics

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages