Skip to content

Commit

Permalink
Beef up docs just a little
Browse files Browse the repository at this point in the history
  • Loading branch information
DeanPDX committed Sep 22, 2024
1 parent 6ebc792 commit f724024
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Dotconfig [![Go Reference](https://pkg.go.dev/badge/github.com/DeanPDX/dotconfig.svg)](https://pkg.go.dev/github.com/DeanPDX/dotconfig)
This package aims to simplify configuration from environment variables. In local development, we can supply a `.env` file with key/value pairs. When deployed, values come from a secret manager. This is similar to [joho/godotenv](https://github.com/joho/godotenv) but the aim here is to not only read the `.env` file but use reflection to produce a config struct.

## Example
Assume a file in the current working directory called `.env` with the following contents:
## Usage
Create a `.env` file in your current working directory with the following contents:

```shell
MAX_BYTES_PER_REQUEST='1024'
Expand Down Expand Up @@ -48,7 +48,9 @@ func Main() {
}
```

If your key value pairs are coming from a source other than a local file, or you want to control file IO yourself, you can call `FromReader` instead and pass in a io.Reader. There is [an example of that in the godoc](https://pkg.go.dev/github.com/DeanPDX/dotconfig#example-FromReader).
So for local dev we can use this `.env` file. But when you deploy your app, you set these values from environment variables / secret managers. Your app that consumes this config struct doesn't have to concern itself with where the values came from.

If your key value pairs are coming from a source other than a file, or you want to control file IO yourself, you can call `FromReader` instead and pass in a `io.Reader`. There is [a runnable example of that in the godoc](https://pkg.go.dev/github.com/DeanPDX/dotconfig#example-FromReader).

## Error Handling
By default, file IO errors in `dotconfig.FromFileName` won't produce an error. This is because when you are running in the cloud with a secret manager, not finding a `.env` file is the happy path. If you want to return errors from `os.Open` you can do so with an option:
Expand Down

0 comments on commit f724024

Please sign in to comment.