Skip to content
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 for custom unmarshaling of strings #29

Merged
merged 11 commits into from
Dec 12, 2023

Conversation

wneessen
Copy link
Contributor

Implemented an interface for custom unmarshaling of strings which allows users to define their own custom type unmarshaling methods. Updated fig_test.go and fig.go to reflect these changes. This update provides a flexible way for users to handle configs with custom types.

Implemented an interface for custom unmarshaling of strings which allows users to define their own custom type unmarshaling methods. Updated fig_test.go and fig.go to reflect these changes. This update provides a flexible way for users to handle configs with custom types.
fig_test.go Outdated Show resolved Hide resolved
fig.go Show resolved Hide resolved
fig.go Show resolved Hide resolved
fig.go Show resolved Hide resolved
fig_test.go Outdated Show resolved Hide resolved
wneessen and others added 5 commits December 10, 2023 19:02
Added "listener_type" field to the server configuration in JSON, YAML, and TOML files. The new field helps initialising the ListenerType field, which is now outside the Server struct in the fig test go file, with the "tcp" value.
The "listener_type" field has moved out of the Server struct and is now directly under the server configuration in the fig test go file. This change simplifies the initialization of the ListenerType field with the "tcp" value in JSON, YAML, and TOML configuration files.
The function setDefaultValue in fig.go has been modified to call setValue unless the value satisfies the StringUnmarshaler interface.
A new custom configuration file, config.yaml, and a corresponding test file, custom_test.go, have been created. This is to serve as example for the custom UnmarshalString interface
This is to make sure that `Test_fig_Load_UseStrict` won't fail due to the previously changed server.* files in `testdata/`
fig.go Outdated Show resolved Hide resolved
fig_test.go Outdated Show resolved Hide resolved
fig_test.go Outdated Show resolved Hide resolved
fig.go Outdated Show resolved Hide resolved
fig.go Outdated Show resolved Hide resolved
fig_test.go Outdated Show resolved Hide resolved
This is so that setEnv can benefit from that functionality as well
Added a check to ensure the reflect.Value is valid before attempting unmarshal. Also, wrapped error message for failed unmarshalling for clearer debugging. These changes will enhance error handling and debugging.
…g_test.go

The UnmarshalString function for the ListenerType has been moved higher up in the fig_test.go code. Updates to error logging formats have also been made for better readability, while unnecessary attributes in the server configuration have been removed.
The UnmarshalString function in fig.go was repositioned for efficiency. An error message for unexpected issues during string unmarshalling was also added.
fig.go Show resolved Hide resolved
@kkyr kkyr merged commit 17cd345 into kkyr:master Dec 12, 2023
1 check failed
@kkyr kkyr mentioned this pull request Dec 12, 2023
@kkyr
Copy link
Owner

kkyr commented Dec 12, 2023

Thanks for the PR, great work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants