https://github.com/ancreny/env-parser
Simple parser to get values from environment
https://github.com/ancreny/env-parser
environment-variables golang golang-package parser
Last synced: 5 months ago
JSON representation
Simple parser to get values from environment
- Host: GitHub
- URL: https://github.com/ancreny/env-parser
- Owner: anCreny
- Created: 2023-10-17T13:06:35.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-09T23:01:02.000Z (over 2 years ago)
- Last Synced: 2024-01-25T14:31:42.628Z (over 2 years ago)
- Topics: environment-variables, golang, golang-package, parser
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# env-parser
## About
This is a simple parser to run through a struct and get env variables appropriate for 'custom' tag value.
## Installing
```bash
go get github.com/anCreny/env-parser
```
## Usage
To use custom tag you should create **EnvParser** first:
```go
func New(tag string, useName, safe bool) *EnvParser
```
* tag - tag name that will be parsed by.
* useName - if a field of a structure want to parse doesn't have the tag, you can manage **parser** behaviour:
* *true* - **parser** use field name like a tag value.
* *false* - ignore field if tag with the given name doesn't exist.
* safe - getting opportunity to manage fields override. If the specific field has a non-zero value:
* *true* - value from env var ___won't___ replace the field value
* *false* - value from env var ___will___ replace the field value
The constructor will return a parser instance of the structure:
```go
type EnvParser struct {
tag string
useName bool
}
```
The structure has only one simple method:
```go
func (e *EnvParser) Parse(structure interface{}) error
```
Method get in a pointer to a structure you want to parse in, instead you will get an error.
***
You'r wellcome to contribute and comment it!
Love you <3