Updated GetDescription function and ReadEnv.#59
Updated GetDescription function and ReadEnv.#59mashinapetro wants to merge 2 commits intoilyakaznacheev:masterfrom
Conversation
Now user can see more userful information then earlier.
In particular, GetDescription function return text with
information with "required" line.
See example below:
Environment variables:
GREETING string
Greeting phrase
Default: "Hello!"
Required: true
DB_HOST string
Database host
Required: true
DB_PORT string
Database port
Required: true
DB_USER string
Database user name
Required: true
DB_PASSWORD string
Database user password
Required: true
DB_NAME string
Database name
Required: true
Error from ReadEnv contains information not only about
structure's field, but about env variables for this field as well.
"field "Host" is required but the value is not provided.
Envs names: "SRV_HOST HOST""
Also, all test changed for the last changes.
Codecov Report
@@ Coverage Diff @@
## master #59 +/- ##
==========================================
+ Coverage 89.79% 89.95% +0.16%
==========================================
Files 1 1
Lines 245 249 +4
==========================================
+ Hits 220 224 +4
Misses 17 17
Partials 8 8
Continue to review full report at Codecov.
|
| @@ -1,4 +1,4 @@ | |||
| module github.com/ilyakaznacheev/cleanenv | |||
| module github.com/mashinapetro/cleanenv | |||
There was a problem hiding this comment.
Please change back to ilyakaznacheev
| envList := "" | ||
| for _, env := range meta.envList { | ||
| envList = envList + env + " " | ||
| } | ||
| envList = strings.Trim(envList, " ") | ||
| err := fmt.Errorf("field %q is required but the value is not provided. Envs names: %q", | ||
| meta.fieldName, envList) |
There was a problem hiding this comment.
We really don't need this part, because the value can come from any source - env, yaml, toml, json, etc. The only thing we know is that the value is empty, and there is a message about it.
Hey, Ilya!
Your project is awesome!
I've tried about 10 similar project, but your is the best.
I propose some changes, which very useful in real production - more informative info from GetDescription method and more information when ReadEnv returns errors.
See detailed description and examples below.
Now user can see more userful information then earlier.
In particular, GetDescription function return text with
information with "required" line.
See example below:
Error from ReadEnv contains information not only about
structure's field, but about env variables for this field as well.
field "Host" is required but the value is not provided. Envs names: "SRV_HOST HOST"Also, all test changed for the last changes.