Sample of my code lies here.
cmd
- executable servicesinternal
- internal implementations of domain models, repositories and use cases with exportable handlersgen
- auto generated codedocs
- auto generated OAS specificationdocker
- docker and docker compose related filespkg
- exportable code
As Go
go run ./cmd/heroes -c config.yaml
OAS documentation, sqlc database queries
# swaggo v2 is required
# go install github.com/swaggo/swag/v2/cmd/swag@latest
#
# sqlc is required
# go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
go generate
Add new migrations via migrate
tool
# go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
migrate create -dir internal/heroes/migrations -ext .sql -seq create_hero_table
Unit tests are built with unit
tag, so to run them use
go test -tags=unit ./...
Run full suite
make test.unit
Integration tests are build with integration
tag, so to run them use
go test -tags=integraition ./...
Run service based suite
# start docker containers required for integration checks
make test.integration.docker.start APP_NAME=heroes
# run tests
make test.integration APP_NAME=heroes
# tear down docker containers
make test.integration.docker.stop APP_NAME=heroes
All services can be configured via ENV
variables or json/yaml
configuration
files passed as argument to the executable.
ENV | json/yaml | Default | Description |
---|---|---|---|
LOGGER_LEVEL |
logger.level |
info |
Define logger base level |
HTTP_ADDR |
http.addr |
:8080 |
Serve http server on that address |
HTTP_GRACEFUL_SHUTDOWN_TIMEOUT |
http.gracefulShutdownTimeout |
20s |
Timeout for active connections graceful shutdown period |
HTTP_READ_TIMEOUT |
http.readTimeout |
20s |
Timeout for incoming connection read state |
HTTP_READ_HEADER_TIMEOUT |
http.readHeaderTimeout |
10s |
Timeout for incoming connection read header state |
HTTP_WRITE_TIMEOUT |
http.writeTimeout |
20s |
Timeout for incoming connection write state |
HTTP_IDLE_TIMEOUT |
http.idleTimeout |
20s |
Timeout for incoming connection idle state |
HTTP_MAX_HEADER_BYTES |
http.maxHeaderBytes |
0 |
Maximum header bytes size for incoming connections |
HTTP_TLS_CERT_FILE |
http.tls.certFile |
"" |
Path to certificate file |
HTTP_TLS_KEY_FILE |
http.tls.keyFile |
"" |
Path to key file |
POSTGRES_HOST |
postgres.host |
127.0.0.1 |
Postgres connection host |
POSTGRES_PORT |
postgres.port |
5432 |
Postgres connection port |
POSTGRES_SSL_MODE |
postgres.sslMode |
disable |
Postgres connection SSL options |
POSTGRES_DB |
postgres.db |
postgres |
Postgres connection database |
POSTGRES_SCHEMA |
postgres.schema |
public |
Postgres connection search path schema and migration target |
POSTGRES_USER |
postgres.user |
postgres |
Postgres connection user |
POSTGRES_PASSWORD |
postgres.password |
postgres |
Postgres connection password |
POSTGRES_MAX_CONNS |
postgres.maxConns |
10 |
Postgres connection pool max size |
POSTGRES_MIN_CONNS |
postgres.minConns |
1 |
Postgres connection pool min size |
POSTGRES_MAX_CONN_LIFETIME |
postgres.maxConnLifetime |
10m |
Postgres pool connection max lifetime |
POSTGRES_MAX_CONN_IDLE_TIME |
postgres.maxConnIdleTime |
1m |
Postgres pool connection max idle time |
POSTGRES_HEALTH_CHECK_PERIOD |
postgres.healthCheckPeriod |
10s |
Postgres pool connection health check period |