Skip to content

Commit 65a1b6d

Browse files
committed
Updated the config documentation to make use of custom templates using my envdoc fork.
This will be changed back to the original version if the custom templates PR is merged there.
1 parent 3f9e1a1 commit 65a1b6d

File tree

9 files changed

+274
-233
lines changed

9 files changed

+274
-233
lines changed

README.md

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,78 @@ There are three primary layers with each depending on the next:
5555

5656
## Configuration
5757

58-
All development configuration values are set as environment variables in a single top-level `.env` file and documented
59-
under their respective main packages. [example.env](example.env) holds an exhaustive (and automatically synced)
60-
representation of what the `.env` file can contain.
61-
62-
- [API config documentation](./cmd/api/config.md)
63-
- [Migrations config documentation](./cmd/migrations/config.md)
58+
All development configuration values are set as environment variables in a single top-level `.env` file.
59+
60+
[example.env](example.env) holds an exhaustive (and automatically synced) representation of what the `.env` file can
61+
contain.
62+
63+
[<!-- envdoc-start id:api -->]: #
64+
65+
### API
66+
67+
| Name | Description | Default | Attributes |
68+
|------|-------------|---------|------------|
69+
| `API_ENVIRONMENT` | Environment specifies the current running environment of the API. | `development` | |
70+
| `API_DEBUG_MODE` | DebugMode enables/disables detailed debugging output. | `false` | |
71+
| `API_SERVER_HTTP_PORT` | HttpPort defines the port number on which the HTTP server will listen for incoming connections. | | `REQUIRED` |
72+
| `API_SERVER_BASE_URL` | BaseUrl specifies the base URL used for constructing server-related endpoints. | | |
73+
| `API_SERVER_IDLE_TIMEOUT` | IdleTimeout is the duration the server will wait for the next request before closing idle connections when keep-alives are enabled. | `1m` | |
74+
| `API_SERVER_READ_TIMEOUT` | ReadTimeout specifies the maximum duration for reading an entire request, including the body. | `5s` | |
75+
| `API_SERVER_WRITE_TIMEOUT` | WriteTimeout defines the maximum duration for writing a response before timing out. | `15s` | |
76+
| `API_SERVER_REQUEST_TIMEOUT` | RequestTimeout specifies the maximum duration for handlers to run.<br>It should be lower than WriteTimeout as no response will be returned if a handler's runtime exceeds the write timeout. | `10s` | |
77+
| `API_SERVER_SHUTDOWN_TIMEOUT` | ShutdownTimeout specifies the duration the server will wait to wrap up active connections and background operations for a graceful shutdown. | `30s` | |
78+
| `API_DB_ADDR` | Host address of the database to connect to. | `localhost` | |
79+
| `API_DB_PORT` | Port of the database to connect to. | `5432` | |
80+
| `API_DB_USER` | User for the database authentication. | | `REQUIRED` |
81+
| `API_DB_PASS` | Pass (password) for the database authentication. | | `REQUIRED` |
82+
| `API_DB_NAME` | Name of the database to connect to. | | `REQUIRED` |
83+
| `API_DB_SSL_MODE` | SslMode of the database connection. | `disable` | |
84+
| `API_DB_MAX_CONNECTIONS` | MaxConns is the maximum connections that can be created by the database connection pool. | `25` | |
85+
| `API_DB_MAX_CONNECTION_LIFETIME` | MaxConnLifetime is the duration since creation after which a connection will be automatically closed. | `2h` | |
86+
| `API_DB_MAX_CONNECTION_IDLE_TIME` | MaxConnIdleTime is the duration after which an idle connection will be automatically closed. | `5m` | |
87+
| `API_CACHE_HOST` | Host specifies the address of the cache server. | `localhost` | |
88+
| `API_CACHE_PORT` | Port defines the port number on which the cache server will listen. | `6379` | |
89+
| `API_CACHE_PASSWORD` | Password of the cache server. | | |
90+
| `API_CACHE_DATABASE` | Database specifies the cache database number to connect to. | `0` | |
91+
| `API_AUTH_JWT_ISSUER` | JwtIssuer specifies the issuer of the JWT, determining the entity responsible for generating the token. | `go-backend-template` | |
92+
| `API_AUTH_JWT_ACCESS_TOKEN_SECRET` | JwtAccessTokenSecret is the secret key used to sign and validate JWT access tokens. | | |
93+
| `API_AUTH_JWT_REFRESH_TOKEN_SECRET` | JwtRefreshTokenSecret is the secret key used to sign and validate JWT refresh tokens. | | |
94+
| `API_AUTH_JWT_ACCESS_TOKEN_DURATION` | JwtAccessTokenDuration defines the lifespan of JWT access tokens before they expire. | `1h` | |
95+
| `API_AUTH_JWT_REFRESH_TOKEN_DURATION` | JwtRefreshTokenDuration specifies the duration for which a JWT refresh token remains valid before expiration. | `12h` | |
96+
| `API_AUTH_OTP_DURATION` | OtpDuration defines the time duration for which an OTP remains valid before expiring. | `30s` | |
97+
| `API_SMTP_HOST` | Host specifies the SMTP server address. | `localhost` | |
98+
| `API_SMTP_PORT` | Port specifies the port number for the SMTP server. | `587` | |
99+
| `API_SMTP_USER` | User specifies the username required for SMTP authentication. | | |
100+
| `API_SMTP_PASSWORD` | Password specifies the password required for SMTP authentication. | | |
101+
| `API_SMTP_SENDER` | Sender defines the email address used as the sender in SMTP communications. | | |
102+
| `API_OTEL_SERVICE_NAME` | ServiceName defines the name of the service used for observability and telemetry. | `go-backend-template` | |
103+
| `API_OTEL_OTLP_GRPC_HOST` | OtlpGrpcHost defines the host address for the OTLP gRPC exporter. | `localhost` | |
104+
| `API_OTEL_OTLP_GRPC_PORT` | OtlpGrpcPort specifies the port number for the OTLP gRPC exporter. | `4317` | |
105+
| `API_OTEL_OTLP_SECURE_CONNECTION` | OtlpSecureConnection determines if a secure (TLS) connection should be used for OTLP communication. | `false` | |
106+
107+
[<!-- envdoc-end id:api -->]: #
108+
109+
[<!-- envdoc-start id:migrations -->]: #
110+
111+
### Migrations
112+
113+
| Name | Description | Default | Attributes |
114+
|------|-------------|---------|------------|
115+
| `MIGRATIONS_ENVIRONMENT` | Environment specifies the current running environment of the database migrations. | `development` | |
116+
| `MIGRATIONS_DEBUG_MODE` | DebugMode enables/disables detailed debugging output. | `false` | |
117+
| `MIGRATIONS_DB_ADDR` | Host address of the database to connect to. | `localhost` | |
118+
| `MIGRATIONS_DB_PORT` | Port of the database to connect to. | `5432` | |
119+
| `MIGRATIONS_DB_USER` | User for the database authentication. | | `REQUIRED` |
120+
| `MIGRATIONS_DB_PASS` | Pass (password) for the database authentication. | | `REQUIRED` |
121+
| `MIGRATIONS_DB_NAME` | Name of the database to connect to. | | `REQUIRED` |
122+
| `MIGRATIONS_DB_SSL_MODE` | SslMode of the database connection. | `disable` | |
123+
| `MIGRATIONS_DB_MAX_CONNECTIONS` | MaxConns is the maximum connections that can be created by the database connection pool. | `25` | |
124+
| `MIGRATIONS_DB_MAX_CONNECTION_LIFETIME` | MaxConnLifetime is the duration since creation after which a connection will be automatically closed. | `2h` | |
125+
| `MIGRATIONS_DB_MAX_CONNECTION_IDLE_TIME` | MaxConnIdleTime is the duration after which an idle connection will be automatically closed. | `5m` | |
126+
127+
[<!-- envdoc-end id:migrations -->]: #
64128

65129
## Todo
66130

67131
- Add more package-level documentation.
68-
- Add tests for more endpoints.
132+
- Add tests for more endpoints.

cmd/api/config.md

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
1-
# Environment Variables
2-
3-
## Config
4-
5-
- `API_ENVIRONMENT` (default: `development`) - Environment specifies the current running environment of the API.
6-
- `API_DEBUG_MODE` (default: `false`) - DebugMode enables/disables detailed debugging output.
7-
- `API_DB_ADDR` (default: `localhost`) - Host address of the database to connect to.
8-
- `API_DB_PORT` (default: `5432`) - Port of the database to connect to.
9-
- `API_DB_USER` (**required**) - User for the database authentication.
10-
- `API_DB_PASS` (**required**) - Pass (password) for the database authentication.
11-
- `API_DB_NAME` (**required**) - Name of the database to connect to.
12-
- `API_DB_SSL_MODE` (default: `disable`) - SslMode of the database connection.
13-
- `API_DB_MAX_CONNECTIONS` (default: `25`) - MaxConns is the maximum connections that can be created by the database connection pool.
14-
- `API_DB_MAX_CONNECTION_LIFETIME` (default: `2h`) - MaxConnLifetime is the duration since creation after which a connection will be automatically closed.
15-
- `API_DB_MAX_CONNECTION_IDLE_TIME` (default: `5m`) - MaxConnIdleTime is the duration after which an idle connection will be automatically closed.
16-
- `API_CACHE_HOST` (default: `localhost`) - Host specifies the address of the cache server.
17-
- `API_CACHE_PORT` (default: `6379`) - Port defines the port number on which the cache server will listen.
18-
- `API_CACHE_PASSWORD` - Password of the cache server.
19-
- `API_CACHE_DATABASE` (default: `0`) - Database specifies the cache database number to connect to.
20-
- `API_SERVER_HTTP_PORT` (**required**) - HttpPort defines the port number on which the HTTP server will listen for incoming connections.
21-
- `API_SERVER_BASE_URL` - BaseUrl specifies the base URL used for constructing server-related endpoints.
22-
- `API_SERVER_IDLE_TIMEOUT` (default: `1m`) - IdleTimeout is the duration the server will wait for the next request before closing idle connections when keep-alives are enabled.
23-
- `API_SERVER_READ_TIMEOUT` (default: `5s`) - ReadTimeout specifies the maximum duration for reading an entire request, including the body.
24-
- `API_SERVER_WRITE_TIMEOUT` (default: `15s`) - WriteTimeout defines the maximum duration for writing a response before timing out.
25-
- `API_SERVER_REQUEST_TIMEOUT` (default: `10s`) - RequestTimeout specifies the maximum duration for handlers to run.
26-
It should be lower than WriteTimeout as no response will be returned if a handler's runtime exceeds the write timeout.
27-
- `API_SERVER_SHUTDOWN_TIMEOUT` (default: `30s`) - ShutdownTimeout specifies the duration the server will wait to wrap up active connections and background operations for a graceful shutdown.
28-
- `API_AUTH_JWT_ISSUER` (default: `go-backend-template`) - JwtIssuer specifies the issuer of the JWT, determining the entity responsible for generating the token.
29-
- `API_AUTH_JWT_ACCESS_TOKEN_SECRET` - JwtAccessTokenSecret is the secret key used to sign and validate JWT access tokens.
30-
- `API_AUTH_JWT_REFRESH_TOKEN_SECRET` - JwtRefreshTokenSecret is the secret key used to sign and validate JWT refresh tokens.
31-
- `API_AUTH_JWT_ACCESS_TOKEN_DURATION` (default: `1h`) - JwtAccessTokenDuration defines the lifespan of JWT access tokens before they expire.
32-
- `API_AUTH_JWT_REFRESH_TOKEN_DURATION` (default: `12h`) - JwtRefreshTokenDuration specifies the duration for which a JWT refresh token remains valid before expiration.
33-
- `API_AUTH_OTP_DURATION` (default: `30s`) - OtpDuration defines the time duration for which an OTP remains valid before expiring.
34-
- `API_SMTP_HOST` (default: `localhost`) - Host specifies the SMTP server address.
35-
- `API_SMTP_PORT` (default: `587`) - Port specifies the port number for the SMTP server.
36-
- `API_SMTP_USER` - User specifies the username required for SMTP authentication.
37-
- `API_SMTP_PASSWORD` - Password specifies the password required for SMTP authentication.
38-
- `API_SMTP_SENDER` - Sender defines the email address used as the sender in SMTP communications.
39-
- `API_OTEL_SERVICE_NAME` (default: `go-backend-template`) - ServiceName defines the name of the service used for observability and telemetry.
40-
- `API_OTEL_OTLP_GRPC_HOST` (default: `localhost`) - OtlpGrpcHost defines the host address for the OTLP gRPC exporter.
41-
- `API_OTEL_OTLP_GRPC_PORT` (default: `4317`) - OtlpGrpcPort specifies the port number for the OTLP gRPC exporter.
42-
- `API_OTEL_OTLP_SECURE_CONNECTION` (default: `false`) - OtlpSecureConnection determines if a secure (TLS) connection should be used for OTLP communication.
1+
# API
432

3+
| Name | Description | Default | Attributes |
4+
|------|-------------|---------|------------|
5+
| `API_ENVIRONMENT` | Environment specifies the current running environment of the API. | `development` | |
6+
| `API_DEBUG_MODE` | DebugMode enables/disables detailed debugging output. | `false` | |
7+
| `API_SERVER_HTTP_PORT` | HttpPort defines the port number on which the HTTP server will listen for incoming connections. | | `REQUIRED` |
8+
| `API_SERVER_BASE_URL` | BaseUrl specifies the base URL used for constructing server-related endpoints. | | |
9+
| `API_SERVER_IDLE_TIMEOUT` | IdleTimeout is the duration the server will wait for the next request before closing idle connections when keep-alives are enabled. | `1m` | |
10+
| `API_SERVER_READ_TIMEOUT` | ReadTimeout specifies the maximum duration for reading an entire request, including the body. | `5s` | |
11+
| `API_SERVER_WRITE_TIMEOUT` | WriteTimeout defines the maximum duration for writing a response before timing out. | `15s` | |
12+
| `API_SERVER_REQUEST_TIMEOUT` | RequestTimeout specifies the maximum duration for handlers to run.<br>It should be lower than WriteTimeout as no response will be returned if a handler's runtime exceeds the write timeout. | `10s` | |
13+
| `API_SERVER_SHUTDOWN_TIMEOUT` | ShutdownTimeout specifies the duration the server will wait to wrap up active connections and background operations for a graceful shutdown. | `30s` | |
14+
| `API_DB_ADDR` | Host address of the database to connect to. | `localhost` | |
15+
| `API_DB_PORT` | Port of the database to connect to. | `5432` | |
16+
| `API_DB_USER` | User for the database authentication. | | `REQUIRED` |
17+
| `API_DB_PASS` | Pass (password) for the database authentication. | | `REQUIRED` |
18+
| `API_DB_NAME` | Name of the database to connect to. | | `REQUIRED` |
19+
| `API_DB_SSL_MODE` | SslMode of the database connection. | `disable` | |
20+
| `API_DB_MAX_CONNECTIONS` | MaxConns is the maximum connections that can be created by the database connection pool. | `25` | |
21+
| `API_DB_MAX_CONNECTION_LIFETIME` | MaxConnLifetime is the duration since creation after which a connection will be automatically closed. | `2h` | |
22+
| `API_DB_MAX_CONNECTION_IDLE_TIME` | MaxConnIdleTime is the duration after which an idle connection will be automatically closed. | `5m` | |
23+
| `API_CACHE_HOST` | Host specifies the address of the cache server. | `localhost` | |
24+
| `API_CACHE_PORT` | Port defines the port number on which the cache server will listen. | `6379` | |
25+
| `API_CACHE_PASSWORD` | Password of the cache server. | | |
26+
| `API_CACHE_DATABASE` | Database specifies the cache database number to connect to. | `0` | |
27+
| `API_AUTH_JWT_ISSUER` | JwtIssuer specifies the issuer of the JWT, determining the entity responsible for generating the token. | `go-backend-template` | |
28+
| `API_AUTH_JWT_ACCESS_TOKEN_SECRET` | JwtAccessTokenSecret is the secret key used to sign and validate JWT access tokens. | | |
29+
| `API_AUTH_JWT_REFRESH_TOKEN_SECRET` | JwtRefreshTokenSecret is the secret key used to sign and validate JWT refresh tokens. | | |
30+
| `API_AUTH_JWT_ACCESS_TOKEN_DURATION` | JwtAccessTokenDuration defines the lifespan of JWT access tokens before they expire. | `1h` | |
31+
| `API_AUTH_JWT_REFRESH_TOKEN_DURATION` | JwtRefreshTokenDuration specifies the duration for which a JWT refresh token remains valid before expiration. | `12h` | |
32+
| `API_AUTH_OTP_DURATION` | OtpDuration defines the time duration for which an OTP remains valid before expiring. | `30s` | |
33+
| `API_SMTP_HOST` | Host specifies the SMTP server address. | `localhost` | |
34+
| `API_SMTP_PORT` | Port specifies the port number for the SMTP server. | `587` | |
35+
| `API_SMTP_USER` | User specifies the username required for SMTP authentication. | | |
36+
| `API_SMTP_PASSWORD` | Password specifies the password required for SMTP authentication. | | |
37+
| `API_SMTP_SENDER` | Sender defines the email address used as the sender in SMTP communications. | | |
38+
| `API_OTEL_SERVICE_NAME` | ServiceName defines the name of the service used for observability and telemetry. | `go-backend-template` | |
39+
| `API_OTEL_OTLP_GRPC_HOST` | OtlpGrpcHost defines the host address for the OTLP gRPC exporter. | `localhost` | |
40+
| `API_OTEL_OTLP_GRPC_PORT` | OtlpGrpcPort specifies the port number for the OTLP gRPC exporter. | `4317` | |
41+
| `API_OTEL_OTLP_SECURE_CONNECTION` | OtlpSecureConnection determines if a secure (TLS) connection should be used for OTLP communication. | `false` | |

cmd/api/internal/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ import (
88

99
const configPrefix = "API_"
1010

11-
//go:generate envdoc -output "../config.md" -types "Config" -env-prefix "API_" -format "markdown"
12-
//go:generate envdoc -output "../config.env" -types "Config" -env-prefix "API_" -format "dotenv"
11+
//go:generate envdoc -output "../config.md" -types "Config" -env-prefix "API_" -template "../../../templates/configdoc.md.go.tmpl" -title "API"
12+
//go:generate envdoc -output "../config.env" -types "Config" -env-prefix "API_" -template "../../../templates/configdoc.dotenv.go.tmpl" -title "API"
1313
type Config struct {
1414
// Environment specifies the current running environment of the API.
1515
Environment string `env:"ENVIRONMENT" envDefault:"development"`
1616

1717
// DebugMode enables/disables detailed debugging output.
1818
DebugMode bool `env:"DEBUG_MODE" envDefault:"false"`
1919

20+
Server ServerConfig
2021
Database DatabaseConfig
2122
Cache CacheConfig
22-
Server ServerConfig
2323
Auth AuthConfig
2424
Smtp SmtpConfig
2525
Otel OtelConfig
@@ -34,7 +34,7 @@ func ParseConfig() *Config {
3434

3535
type ServerConfig struct {
3636
// HttpPort defines the port number on which the HTTP server will listen for incoming connections.
37-
HttpPort int `env:"SERVER_HTTP_PORT,required"`
37+
HttpPort int `env:"SERVER_HTTP_PORT,notEmpty"`
3838

3939
// BaseUrl specifies the base URL used for constructing server-related endpoints.
4040
BaseUrl string `env:"SERVER_BASE_URL"`
@@ -66,13 +66,13 @@ type DatabaseConfig struct {
6666
Port string `env:"DB_PORT" envDefault:"5432"`
6767

6868
// User for the database authentication.
69-
User string `env:"DB_USER,required"`
69+
User string `env:"DB_USER,notEmpty"`
7070

7171
// Pass (password) for the database authentication.
72-
Pass string `env:"DB_PASS,required"`
72+
Pass string `env:"DB_PASS,notEmpty"`
7373

7474
// Name of the database to connect to.
75-
Name string `env:"DB_NAME,required"`
75+
Name string `env:"DB_NAME,notEmpty"`
7676

7777
// SslMode of the database connection.
7878
SslMode string `env:"DB_SSL_MODE" envDefault:"disable"`

cmd/migrations/config.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
# Environment Variables
2-
3-
## Config
4-
5-
- `MIGRATIONS_ENVIRONMENT` (default: `Development`) - Environment specifies the current running environment of the database migrations.
6-
- `MIGRATIONS_DEBUG_MODE` (default: `false`) - DebugMode enables/disables detailed debugging output.
7-
- `MIGRATIONS_DB_ADDR` (default: `localhost`) - Host address of the database to connect to.
8-
- `MIGRATIONS_DB_PORT` (default: `5432`) - Port of the database to connect to.
9-
- `MIGRATIONS_DB_USER` (**required**) - User for the database authentication.
10-
- `MIGRATIONS_DB_PASS` (**required**) - Pass (password) for the database authentication.
11-
- `MIGRATIONS_DB_NAME` (**required**) - Name of the database to connect to.
12-
- `MIGRATIONS_DB_SSL_MODE` (default: `disable`) - SslMode of the database connection.
13-
- `MIGRATIONS_DB_MAX_CONNECTIONS` (default: `25`) - MaxConns is the maximum connections that can be created by the database connection pool.
14-
- `MIGRATIONS_DB_MAX_CONNECTION_LIFETIME` (default: `2h`) - MaxConnLifetime is the duration since creation after which a connection will be automatically closed.
15-
- `MIGRATIONS_DB_MAX_CONNECTION_IDLE_TIME` (default: `5m`) - MaxConnIdleTime is the duration after which an idle connection will be automatically closed.
1+
# Migrations
162

3+
| Name | Description | Default | Attributes |
4+
|------|-------------|---------|------------|
5+
| `MIGRATIONS_ENVIRONMENT` | Environment specifies the current running environment of the database migrations. | `development` | |
6+
| `MIGRATIONS_DEBUG_MODE` | DebugMode enables/disables detailed debugging output. | `false` | |
7+
| `MIGRATIONS_DB_ADDR` | Host address of the database to connect to. | `localhost` | |
8+
| `MIGRATIONS_DB_PORT` | Port of the database to connect to. | `5432` | |
9+
| `MIGRATIONS_DB_USER` | User for the database authentication. | | `REQUIRED` |
10+
| `MIGRATIONS_DB_PASS` | Pass (password) for the database authentication. | | `REQUIRED` |
11+
| `MIGRATIONS_DB_NAME` | Name of the database to connect to. | | `REQUIRED` |
12+
| `MIGRATIONS_DB_SSL_MODE` | SslMode of the database connection. | `disable` | |
13+
| `MIGRATIONS_DB_MAX_CONNECTIONS` | MaxConns is the maximum connections that can be created by the database connection pool. | `25` | |
14+
| `MIGRATIONS_DB_MAX_CONNECTION_LIFETIME` | MaxConnLifetime is the duration since creation after which a connection will be automatically closed. | `2h` | |
15+
| `MIGRATIONS_DB_MAX_CONNECTION_IDLE_TIME` | MaxConnIdleTime is the duration after which an idle connection will be automatically closed. | `5m` | |

0 commit comments

Comments
 (0)