-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from g4s8/nested-lists
feat: add envPrefix nested env vars lists
- Loading branch information
Showing
20 changed files
with
707 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
package main | ||
|
||
// Settings is the application settings. | ||
// | ||
//go:generate go run ../ -output envprefix.txt -format plaintext -type Settings | ||
//go:generate go run ../ -output envprefix.md -type Settings | ||
//go:generate go run ../ -output envprefix.html -format html -type Settings | ||
type Settings struct { | ||
// Database is the database settings | ||
Database Database `envPrefix:"DB_"` | ||
|
||
// Server is the server settings | ||
Server ServerConfig `envPrefix:"SERVER_"` | ||
|
||
// Debug is the debug flag | ||
Debug bool `env:"DEBUG"` | ||
} | ||
|
||
// Database is the database settings. | ||
type Database struct { | ||
// Port is the port to connect to | ||
Port Int `env:"PORT,required"` | ||
// Host is the host to connect to | ||
Host string `env:"HOST,notEmpty" envDefault:"localhost"` | ||
// User is the user to connect as | ||
User string `env:"USER"` | ||
// Password is the password to use | ||
Password string `env:"PASSWORD"` | ||
// DisableTLS is the flag to disable TLS | ||
DisableTLS bool `env:"DISABLE_TLS"` | ||
} | ||
|
||
// ServerConfig is the server settings. | ||
type ServerConfig struct { | ||
// Port is the port to listen on | ||
Port Int `env:"PORT,required"` | ||
|
||
// Host is the host to listen on | ||
Host string `env:"HOST,notEmpty" envDefault:"localhost"` | ||
|
||
// Timeout is the timeout settings | ||
Timeout TimeoutConfig `envPrefix:"TIMEOUT_"` | ||
} | ||
|
||
// TimeoutConfig is the timeout settings. | ||
type TimeoutConfig struct { | ||
// Read is the read timeout | ||
Read Int `env:"READ" envDefault:"30"` | ||
// Write is the write timeout | ||
Write Int `env:"WRITE" envDefault:"30"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Environment Variables</title> | ||
<style> | ||
* { | ||
box-sizing: border-box; | ||
} | ||
body { | ||
font-family: sans-serif; | ||
color: #1F2328; | ||
} | ||
article { | ||
margin-left: auto; | ||
margin-right: auto; | ||
max-width: 1012px; | ||
font-size: 16px; | ||
line-height: 1.5; | ||
word-wrap: break-word; | ||
display: block; | ||
padding: 32px; | ||
} | ||
article::first-child { | ||
margin-top: 0 !important; | ||
} | ||
article::last-child { | ||
margin-bottom: 0 !important; | ||
} | ||
section { | ||
margin-top: 46px; | ||
background-color: #ffffff; | ||
border: 0px; | ||
border-radius: 0px 0px 6px 6px; | ||
padding: 0px; | ||
min-width: 0px; | ||
margin-top: 46px; | ||
-moz-box-pack: center; | ||
} | ||
h1, h2 { | ||
margin-top: 24px; | ||
margin-bottom: 16px; | ||
line-height: 1.25; | ||
font-weight: 600; | ||
padding-bottom: .3em; | ||
border-bottom: 1px solid hsla(210,18%,87%,1); | ||
} | ||
h1 { | ||
font-size: 2em; | ||
} | ||
h2 { | ||
font-size: 1.5em; | ||
} | ||
li { | ||
margin-top: .25em; | ||
} | ||
li code { | ||
padding: .2em .4em; | ||
margin: 0; | ||
font-size: 85%; | ||
white-space: break-sp#ffffffaces; | ||
background-color: rgba(175,184,193,0.2); | ||
border-radius: 6px; | ||
} | ||
li strong { | ||
font-weight: 600; | ||
} | ||
p { | ||
margin-top: 0; | ||
margin-bottom: 16px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<section> | ||
<article> | ||
<h1>Environment Variables</h1> | ||
|
||
<h2>Settings</h2> | ||
<p>Settings is the application settings.</p> | ||
<ul> | ||
<li>Database is the database settings. | ||
<ul> | ||
<li><code>DB_PORT</code> (<strong>required</strong>) - Port is the port to connect to</li> | ||
<li><code>DB_HOST</code> (<strong>required</strong>, non-empty, default: <code>localhost</code>) - Host is the host to connect to</li> | ||
<li><code>DB_USER</code> - User is the user to connect as</li> | ||
<li><code>DB_PASSWORD</code> - Password is the password to use</li> | ||
<li><code>DB_DISABLE_TLS</code> - DisableTLS is the flag to disable TLS</li> | ||
</ul> | ||
</li> | ||
<li>ServerConfig is the server settings. | ||
<ul> | ||
<li><code>SERVER_PORT</code> (<strong>required</strong>) - Port is the port to listen on</li> | ||
<li><code>SERVER_HOST</code> (<strong>required</strong>, non-empty, default: <code>localhost</code>) - Host is the host to listen on</li> | ||
<li>TimeoutConfig is the timeout settings. | ||
<ul> | ||
<li><code>SERVER_TIMEOUT_READ</code> (default: <code>30</code>) - Read is the read timeout</li> | ||
<li><code>SERVER_TIMEOUT_WRITE</code> (default: <code>30</code>) - Write is the write timeout</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
</li> | ||
<li><code>DEBUG</code> - Debug is the debug flag</li> | ||
</ul> | ||
|
||
</article> | ||
</section> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Environment Variables | ||
|
||
## Settings | ||
|
||
Settings is the application settings. | ||
|
||
* Database is the database settings. | ||
* `DB_PORT` (required) - Port is the port to connect to | ||
* `DB_HOST` (required, non-empty, default: `localhost`) - Host is the host to connect to | ||
* `DB_USER` - User is the user to connect as | ||
* `DB_PASSWORD` - Password is the password to use | ||
* `DB_DISABLE_TLS` - DisableTLS is the flag to disable TLS | ||
* ServerConfig is the server settings. | ||
* `SERVER_PORT` (required) - Port is the port to listen on | ||
* `SERVER_HOST` (required, non-empty, default: `localhost`) - Host is the host to listen on | ||
* TimeoutConfig is the timeout settings. | ||
* `SERVER_TIMEOUT_READ` (default: `30`) - Read is the read timeout | ||
* `SERVER_TIMEOUT_WRITE` (default: `30`) - Write is the write timeout | ||
* `DEBUG` - Debug is the debug flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package main | ||
|
||
import "fmt" | ||
|
||
const debugLogs = false | ||
|
||
func debug(f string, args ...any) { | ||
if !debugLogs { | ||
return | ||
} | ||
fmt.Printf("DEBUG: "+f+"\n", args...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.