- Rest service based on Gin and Fizz for OpenApi spec generation
- Basic healthcheck (ping handler) (in
commonpackage) - Swagger UI available on
http://localhost:8080/swaggeran Open API spec onhttp://localhost:8080/openapi.json - serving Prometheus metrics on
http://localhost:10250/metrics - custom metrics defined in metrics.go
- unit test for handlers in pkg/server/router_test.go
- service-test tests in /test/stest. Refer to service tests repo for more info
- Dockerfiles for service and service test
- Basic configuration config.go based on config package
- CI with Github Actions
- Github actions for publishing docker image with versioning( tags set to
github-shaandbranch-[build-number]). Separate tags used for application and test image
- run unit tests
go test ./... -v - run server
go run cmd/server/main.go - run service tests from another terminal
go test ./test/stest -tags servicetest -v -count=1 - Send PUT request:
curl -X 'PUT' 'http://localhost:8080/things/first-thing' \
-d '{ "value": "thing value" }'
- Send GET request
curl 'http://localhost:8080/things/first-thing'
- Check swagger
http://localhost:8080/swagger - Check Open API spec
http://localhost:8080/openapi.json - Check Prometheus metrics
http://localhost:10250/metrics
- run service
docker run -p 8080:8080 -p 10250:10250 orsol/go-rest-service-template:latest - try steps from 3 to the end from Try it section
- Copy whole directory
- Replace
rest-servicewith your service name everywhere in the project. Including Dockerfiles, Makefile and go.mod - Adjust paths in go.mod according to the location of your project
- Adjust import paths if needed
- run
go mod tidy - update routes and handlers in pkg/server/router.go defining API objects in pkg/server/api.go
- Define you configuration structure in pkg/config.go