-
Notifications
You must be signed in to change notification settings - Fork 13
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of HJSON #5
Comments
An input string would not work together with giving flags to specify the
config file.
I might make encodings more generic by using an interface like `type
FileEncoding func(content []byte) (map[string]interface{}, error)` and then
define global vars for JSON, YAML and TOML and allow users to put a custom
encoding function.
Let me look into that tomorrow.
…On 22 Oct 2017 14:39, "Christophe Meessen" ***@***.***> wrote:
Could it be possible to add support of hjson <https://hjson.org/> by mean
of the HJSON-go <https://github.com/hjson/hjson-go> package ?
hjson is human friendly json. This means a json encoding more convenient
for humans to read and write. The best way to use it is to convert the
hjson string into json, and than use the json decoding.
An alternate solution would be to support a string as config input instead
of a file. This would allow users to any type of source for the config. It
could be extracted from a database for instance.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#5>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AA0F3NnizCATGKRkjz7W3XwA7LD0XReHks5suzeBgaJpZM4QB7vV>
.
|
Look at this commit: c814583 I think it's ok for you to specify a custom decoder for HJSON. I don't think HJSON is common enough to be worth it maintaining it in the package. You can create a function like here: c814583#diff-3b7b9b0c1df08c66e0e7ffb8929051d1R23 |
The DecoderTryAll is a brute force solution. |
Well, TryAll is only used when no decoder is provided in Conf here: c814583#diff-b67b03abee47ec66b6b9d0e2302a2576R35 So yes it's brute force last resort. I'm quite impartial for removing it and panicing if no decoder is provided in the Conf struct. |
I believe this is solved. gonfig supports custom config file decoders. F.e. for hjson, one could make one like this: // DecoderHJSON is an HJSON decoding function for config files.
var DecoderHJSON = func(c []byte) (map[string]interface{}, error) {
var m map[string]interface{}
if err := hjson.Unmarshal(c, &m); err != nil {
return nil, fmt.Errorf("error parsing HJSON config file: %s", err)
}
return m, nil
} And pass it to gonfig.Load(&config, gonfig.Conf{
FileDecoder: DecoderHJSON,
} |
Could it be possible to add support of hjson by mean of the HJSON-go package ?
hjson is human friendly json. This means a json encoding more convenient for humans to read and write. The best way to use it is to convert the hjson string into json, and than use the json decoding.
An alternate solution would be to support a string as config input instead of a file. This would allow users to any type of source for the config. It could be extracted from a database for instance.
The text was updated successfully, but these errors were encountered: