Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ammerzon/mc523-golang-rest

Second exercise for the subject MC523 SS21 at FH OΓ– Campus Hagenberg.
https://github.com/ammerzon/mc523-golang-rest

golang microservice postgres postgresql rest

Last synced: about 1 month ago
JSON representation

Second exercise for the subject MC523 SS21 at FH OΓ– Campus Hagenberg.

Awesome Lists containing this project

README

        

# Microservices in Go

[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ammerzon_MC523-golang-rest&metric=alert_status)](https://sonarcloud.io/dashboard?id=ammerzon_MC523-golang-rest) [![Build Status](https://www.travis-ci.com/ammerzon/MC523-golang-rest.svg?branch=main)](https://www.travis-ci.com/ammerzon/MC523-golang-rest)

Second exercise for the subject MC523 SS21 at FH OΓ– Campus Hagenberg based on the blog post [Building and Testing a REST API in Go with Gorilla Mux and PostgreSQL](https://semaphoreci.com/community/tutorials/building-and-testing-a-rest-api-in-go-with-gorilla-mux-and-postgresql).

## πŸ“ Requirements

- `go`
- `docker`
- `docker-compose`
- `skaffold`
- `helm`
- `kubectl`

## πŸš€ Get started

```bash
make run-docker
```

## ⚠️ Limitations

* This is a demo application and therefore does ignore common security practices.

## ☸️ Kubernetes Deployment

Your `kubectl` must be configured correctly. For local deployment [minikube](https://minikube.sigs.k8s.io/docs/) or [Kind](https://kind.sigs.k8s.io/docs/user/quick-start/) can be used.

1. Deploy the application
```bash
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
skaffold run
```

2. Forward to a local port
```bash
kubectl port-forward deployment/backend 8010:8010 -n golang-rest
```

3. Create the schema and insert test data

## ♻️ Refactorings

### Folder structure
To blog proposed the following structure:

```shell
.
β”œβ”€β”€ app.go
β”œβ”€β”€ main.go
β”œβ”€β”€ main_test.go
β”œβ”€β”€ model.go
β”œβ”€β”€ go.sum
└── go.mod
```

The current implementation reorganized the folder structure in the following way and added Docker support:

```shell
.
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ cmd
β”‚ β”œβ”€β”€ main.go
β”‚ └── main_test.go
β”œβ”€β”€ db
β”‚ └── schema.sql
β”œβ”€β”€ docker-compose.yaml
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
└── internal
β”œβ”€β”€ config
β”œβ”€β”€ models
└── services
```

### Features

* Added a product search endpoint (`/search/product`)
* Added a price range filter to the `/product` endpoint
* Added a sort option to the `/product` endpoint