Golang application template. Based on clean architecture principles
internal/domain- business models and rulesinternal/app- "App" applicaiton setupinternal/usecase- business logic implementations through usecase and repository interfacesinternal/controller- controllers implementations that orchestrate various usecasesmigrations- application migrationsconfig- application configuration structs and helperspkg- additional, non-dependant infrastructure and logic that can be also used externaly, outside of current project scopecmd- entrypoints to the applicationsembed.go- files and directories that have to be embeded into the applications (migrations for ex.)gen- autogenerated stubs
- Go 1.19
- Docker
Highly extensible Go source code linter providing checks currently missing from other linters.
go install github.com/go-critic/go-critic/cmd/gocritic@latestFast 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@latestInspects source code for security problems by scanning the Go AST.
go install github.com/securego/gosec/v2/cmd/gosec@latestSwag converts Go annotations to Swagger Documentation 2.0.
go install github.com/swaggo/swag/cmd/swag@latestDatabase migrations written in Go. Use as CLI or import as library.
go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latestDefault path for migrations folder is migrations/$(APP_NAME)
To create new migration
make migrate.create MIGRATIONS_FOLDER=migrations/my_app NAME=create_my_tableTo apply migrations
make migrate.upTo reverse migrations
make migrate.downTo force migrations up to a certain version
make migrate.force VERSION=000003To test, build and run application
make runTo start project within docker network
make docker.runTo stop
make docker.stopTo build application docker image
make docker.buld.appYou 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.appTo stop application
make docker.stop.appTo start postgres instance
make docker.run.postgresTo stop
make docker.stop.postgresTo start redis instance
make docker.run.redisTo stop
make docker.stop.redisLOGGER_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"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{
"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"
}
}