Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ create-migration:
goose -dir ./migrations create $$name sql

swagger:
swag init -g ./cmd/api/v1/main.go -o ./docs
mkdir -p docs
swag init -o docs --dir ./cmd,./internal/handler,./internal/controller,./internal/model
30 changes: 29 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,32 @@ goose -dir ./migrations $(DB_DRIVER) $(DB_STRING) up

```
go run cmd/main.go
```
```

## API

The project features a simple CRUD API for users. It has a JSON logger middleware and an X-Api-Key middleware for authentication.

The project also contains terraform scripts for setting up AKS cluster in Azure. (Read more from readme at ./platform/terraform)

There is also k8s-ingress setup which allows any deployment in the AKS cluster to be accessible through https and with a DNS. (Read more from readme at ./platform/terraform)

The API itself has been deployed to the AKS cluster, manifests are in k8s folder.

## Pipeline

There are three workflows
- go - simple CI pipeline that runs
- build
- test
- vet
- fmt
- lint
- gosec
- build-and-deploy
- builds a docker image
- pushes image to docker hub
- runs database migrations with goose
- applies kubernetes manifests to deploy API and postgres
- db-migrate-down
- manually startable workflow in case a db rollback is required
15 changes: 14 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// @title Users API
// @version 1.0
// @description This is a CRUD API for users.

// @BasePath /api/v1

// @securityDefinitions.apikey ApiKeyAuth
// @in header
// @name X-Api-Key

// @externalDocs.description OpenAPI
// @externalDocs.url https://swagger.io/resources/open-api/

package main

import (
Expand Down Expand Up @@ -58,7 +71,7 @@ func main() {
controllers := controller.NewController(services)

loggerMiddleware := middleware.NewLoggerMiddleWare(logger)
apiKeyMiddleware := middleware.NewApiKeyMiddleware(apiKey, []string{"/healthz"})
apiKeyMiddleware := middleware.NewApiKeyMiddleware(apiKey, []string{"/healthz", "/swagger/*any"})

r := gin.New()
r.Use(gin.Recovery())
Expand Down
Loading