Ability for set initor#796
Open
maniak89 wants to merge 1 commit intogoccy:masterfrom
Open
Conversation
|
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #796 +/- ##
==========================================
- Coverage 77.97% 76.91% -1.07%
==========================================
Files 22 22
Lines 8108 8268 +160
==========================================
+ Hits 6322 6359 +37
- Misses 1370 1479 +109
- Partials 416 430 +14 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In some cases, special initialization of slices, structs, and maps is required. For example, allocating a slice from sync.Pool or setting default values for structs in a slice where the number of elements is unknown in advance, so that the external YAML file does not contain anchor tags, etc.
Of course, you can use StructValidator, but it has a number of drawbacks, such as:
Custom unmarshalers can also be used to set default values, but this requires a significant amount of duplicate code that must be maintained as new types are added.
You can use something like https://github.com/mcuadros/go-defaults to set default values, eliminating the need to add wrappers or custom marshalers.
An initator is used to implement the pool/default values.
During initialization, it's often necessary to know how the decoder was initialized, as this can depend on various situations. Therefore, methods for retrieving decoder settings were added.
No new tests were added, as the code is essentially already covered by existing tests.