Home

Awesome

App Mentioned in Awesome Fiber

Golang application template. Based on clean architecture principles

List of contents

Project requirements

Install Go helpers

gocritic

Highly extensible Go source code linter providing checks currently missing from other linters.

go install github.com/go-critic/go-critic/cmd/gocritic@latest

golangci-lint

Fast Go linters runner. It runs linters in parallel, uses caching, supports yaml config, has integrations with all major IDE and has dozens of linters included.

go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

gosec

Inspects source code for security problems by scanning the Go AST.

go install github.com/securego/gosec/v2/cmd/gosec@latest

swag

Swag converts Go annotations to Swagger Documentation 2.0.

go install github.com/swaggo/swag/cmd/swag@latest

migrate

Database migrations written in Go. Use as CLI or import as library.

go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

Makefile

Postgres migrations

Default path for migrations folder is migrations/$(APP_NAME)

To create new migration

make migrate.create MIGRATIONS_FOLDER=migrations/my_app NAME=create_my_table

To apply migrations

make migrate.up

To reverse migrations

make migrate.down

To force migrations up to a certain version

make migrate.force VERSION=000003

Application

To test, build and run application

make run

Docker

To start project within docker network

make docker.run

To stop

make docker.stop

Application

To build application docker image

make docker.buld.app

You can also override build args to access GOPRIVATE repositories inside container

make docker.app.build GOPRIVATE="" GOPRIVATE_USER="" GOPRIVATE_PAT="" GOPRIVATE_SCHEMA=""

To start application

make docker.run.app

To stop application

make docker.stop.app

Postgres

To start postgres instance

make docker.run.postgres

To stop

make docker.stop.postgres

Redis

To start redis instance

make docker.run.redis

To stop

make docker.stop.redis

Configuration

env

LOGGER_LEVEL="info" # standard logger level options (panic, fatal, warn/warning, info, debug, trace)

HTTP_HOST="0.0.0.0"
HTTP_PORT="8000"
HTTP_TIMEOUT="4s"
HTTP_PREFIX=""
HTTP_API_PATH="/api"

TLS_CERT_FILEPATH=""
TLS_KEY_FILEPATH=""

POSTGRES_HOST="127.0.0.1"
POSTGRES_PORT="5432"
POSTGRES_SSL_MODE="disable"
POSTGRES_DB="postgres"
POSTGRES_USER="postgres"
POSTGRES_PASSWORD="postgres"
POSTGRES_MAX_CONNS="10"
POSTGRES_MIN_CONNS="2"
POSTGRES_MAX_CONN_LIFETIME="10m"
POSTGRES_MAX_CONN_IDLE_TIME="1m"
POSTGRES_HEALTH_CHECK_PERIOD="10s"

REDIS_HOST="127.0.0.1"
REDIS_PORT="6379"
REDIS_USERNAME=""
REDIS_PASSWORD=""
REDIS_DB="0"

SWAGGER_HOST="127.0.0.1:8888"
SWAGGER_BASE_PATH="/api"

yaml

logger:
    level: info
http:
    host: 0.0.0.0
    port: 8000
    timeout: 4s
    prefix: ""
    apiPath: /api
tls:
  cert:
    filepath: ""
  key:
    filepath: ""
postgres:
    host: 127.0.0.1
    port: 5432
    sslMode: disable
    db: postgres
    user: postgres
    maxConns: 10
    minConns: 2
    maxConnLifetime: 10m
    maxConnIdleTime: 1m
    healthCheckPeriod: 10s
redis:
    host: 127.0.0.1
    port: 6379
    username: ""
    password: ""
    db: 0
swagger:
  host: 127.0.0.1:8888
  basePath: /api

json

{
    "logger": {
        "level": "info",
        "file": {
            "path": "",
            "name": "",
            "max_age": "24h",
            "rotation_time": "168h"
        },
        "format": {
            "type": "text",
            "caller": false,
            "pretty": false
        }
    },
    "http": {
        "host": "0.0.0.0",
        "port": "8000",
        "timeout": "4s",
        "prefix": "",
        "api_path": "/api"
    },
    "tls": {
      "cert": {
        "filepath": "",
      },
      "key": {
        "filepath": "",
      }
    },
    "postgres": {
        "host": "127.0.0.1",
        "port": "5432",
        "ssl_mode":"disable",
        "db": "postgres",
        "user": "postgres",
        "max_conns": 10,
        "min_conns": 2,
        "max_conn_lifetime": "10m",
        "max_conn_idle_time": "1m",
        "health_check_period": "10s"
    },
    "redis": {
        "host": "127.0.0.1",
        "port": "6379",
        "username": "",
        "password": "",
        "db": 0
    },
    "swagger": {
      "host": "127.0.0.1:8888",
      "base_path": "/api"
    }
}