Replies: 1 comment 5 replies
-
Hello and thank you for your suggestion! You may not know about this, but this is already a feature: Line 83 in f9a153a When the config is loaded, the types of each entry, if eligible, is converted to its expected type as defined in the I invite you to participate to this discussion that suggests an even better solution that would leverage the much more powerful validation system. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Because integers in json are not always asserted to be of type int
i have config.json
when i get
redis.port
the program will panic
panic: config entry "redis.port" is not an int
.so, I modified GetInt():
and got the output
Obviously, its type is string. But string can be converted to int type by using the strconv library method, like this
If the value type is int, it is returned directly. If the value type is string, it attempts to convert it. If successful, it returns the converted value, otherwise it throws a panic. I tried it in my application and it was successful
Beta Was this translation helpful? Give feedback.
All reactions