https://github.com/yuseferi/envyaml
env Yaml is a configuration loader from Yaml file with enviromental variable that helps to have secret placeholders in yaml file.
https://github.com/yuseferi/envyaml
Last synced: about 2 months ago
JSON representation
env Yaml is a configuration loader from Yaml file with enviromental variable that helps to have secret placeholders in yaml file.
- Host: GitHub
- URL: https://github.com/yuseferi/envyaml
- Owner: yuseferi
- License: gpl-3.0
- Created: 2024-09-18T14:36:39.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-09-19T21:39:41.000Z (about 1 year ago)
- Last Synced: 2024-09-20T06:42:18.235Z (about 1 year ago)
- Language: Go
- Size: 43 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
- awesome-go-plus - envyaml - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml.  (Configuration / Standard CLI)
- fucking-awesome-go - envyaml - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml. (Configuration / Standard CLI)
- awesome-go - envyaml - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml. (Configuration / Standard CLI)
- awesome-go - envyaml - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml. (Configuration / Standard CLI)
- awesome-go-with-stars - envyaml - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml. (Configuration / Standard CLI)
- trackawesomelist - envyaml (⭐10) - Yaml with environment variables reader. it helps to have secrets as environment variable but load them configs as structured Yaml. (Recently Updated / [Dec 24, 2024](/content/2024/12/24/README.md))
- awesome-go-cn - envyaml
README
# envYaml (Yaml with environment value loader)
[](https://codecov.io/github/yuseferi/envyaml)
[](https://github.com/yuseferi/envyaml/actions/workflows/ci.yml)
[](https://www.gnu.org/licenses/agpl-3.0)

[](https://goreportcard.com/report/github.com/yuseferi/envyaml)
![]()
Storing application configuration in YAML files offers a clean and straightforward solution, but it's crucial to avoid exposing sensitive data like passwords and API keys. Environment variables provide a secure way to store secrets, preventing them from leaking into your codebase.
The **envyaml** package bridges this gap, allowing you to seamlessly integrate environment variables into your YAML configuration. No more plain-text secrets or complex workarounds! Simply reference environment variables within your YAML file using placeholders, and envyaml will handle the rest, securely substituting the values during parsing.
With **envyaml**, you can:
- Keep your configuration clean and organized in YAML.
- Protect sensitive data by storing it in environment variables.
- Enjoy a simple and intuitive integration process.
- No more compromising between convenience and security. **envyaml** empowers you to manage your application configuration effectively while keeping your secrets safe.## Installation
To install envyaml, use `go get`:
```
go get github.com/yuseferi/envyaml@latest
```## Usage
### Example 1: Error on required env variable
```go
type TestConfig struct {
Host string `yaml:"host" env:"TEST_HOST"`
Port int `yaml:"port" env:"TEST_PORT"`
Password string `yaml:"password" env:"TEST_PASSWORD,required"`
}// Load the configuration
var cfg TestConfig
// assume your configs are in `config.yml` file and this is its content:
//host: localhost
//port: 3606
//password: ${TEST_PASSWORD}
err := envyaml.LoadConfig("config.yml", &cfg)
if err != nil {
log.Fatalln(err)
}
fmt.Println(cfg)
```Error `failed to parse environment variables: env: required environment variable "TEST_PASSWORD" is not set` is expected because this variable has not been set.
### Example 2: When env is defined
```go
type TestConfig struct {
Host string `yaml:"host" env:"TEST_HOST"`
Port int `yaml:"port" env:"TEST_PORT"`
Password string `yaml:"password" env:"TEST_PASSWORD,required"`
}// Load the configuration
var cfg TestConfig
// assume your configs are in `config.yml` file and this is its content:
//host: localhost
//port: 3606
//password: ${TEST_PASSWORD}
_ = os.Setenv("TEST_PASSWORD", "envyaml_pass")
err := envyaml.LoadConfig("config.yml", &cfg)
if err != nil {
log.Fatalln(err)
log.Fatalln(err)log.Fatalln(err)
}
fmt.Println(cfg)
```Expected output:
```
{localhost 3606 envyaml_pass}
```## Development
This project uses [Task](https://taskfile.dev) for managing development tasks. Make sure you have Task installed on your system.
### Available Tasks
- `task build`: Build the project
- `task test`: Run tests
- `task test-coverage`: Run tests with coverage and generate a coverage report
- `task clean`: Clean up generated files
- `task all`: Run all tasks (build, test, and coverage)To run a task, use the `task` command followed by the task name. For example:
```
task build
```### Running Tests
To run tests:
```
task test
```To run tests with coverage:
```
task test-coverage
```This will generate a coverage report in HTML format (`coverage.html`).
## Contributing
We strongly believe in open-source ❤️😊. Please feel free to contribute by raising issues and submitting pull requests to make envYaml even better!
## License
Released under the [GNU GENERAL PUBLIC LICENSE](LICENSE).