modulepackage
0.0.0-20230309142113-a0fbff082e39
Repository: https://github.com/gbeletti/service-golang.git
Documentation: pkg.go.dev
# README
service-golang
This is a simple example to build a microservice in Go. It has an HTTP server and RabbitMQ client packages.
Running it
The service needs MongoDB and RabbitMQ to run succesfully. Let's use docker-compose
to run those servers.
docker-compose up -d mongodb rabbitmq
And now you can build and run the server:
go build && ./service-golang
Creating and image with docker
To run as a service we can create an image and use docker-compose to start the containers. First the image:
docker build . -t service:latest
Now we can run all the servers together using docker-compose
.
docker-compose up -d
Accessing the API
To see a Hello World: localhost:8000.
To check the bitcoin variation on a period: localhost:8000/bitcoin/startdate/YYYY-MM-DD/enddate/YYYY-MM-DD
Stopping the services
Again with docker-compose
:
docker-compose down
# Packages
Package cryptoasset contains the calculus for bitcoin variation day by day.
Package dbmongo has the mongoDB client as singleton.
Package httpserver contains the HTTP server and the routes.
Package queuerabbit contains all the RabbitMQ setup.
Package servicemanager contains the functions to control the service shutdown.