-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
settings,*: use the option pattern with the setting register functions
TLDR: this patch introduces the "functional option style" in the settings API. For example, this call: ```go var s = func() *settings.BoolSetting { s := settings.RegisterBoolSetting(...).WithPublic() s.SetReportable(true) }() ``` can now be written as: ```go var s = settings.RegisterBoolSetting(..., settings.WithPublic, settings.WithReportable(true), ) ``` Internally, the register function now take a last argument of type `...SettingOption`. The following options are defined: ```go var Retired SettingOption var WithPublic SettingOption func WithReportable(reportable bool) SettingOption func WithVisibility(v Visibility) SettingOption func WithValidateDuration(fn func(time.Duration) error) SettingOption // NEW var NonNegativeDuration SettingOption var PositiveDuration SettingOption func NonNegativeDurationWithMaximum(maxValue time.Duration) SettingOption func DurationWithMinimum(minValue time.Duration) SettingOption // RENAMED func DurationWithMinimumOrZeroDisable(minValue time.Duration) SettingOption // NEW func DurationInRange(minVal, maxVal int64) SettingOption // NEW func WithValidateFloat(fn func(float64) error) SettingOption // NEW var NonNegativeFloat SettingOption var PositiveFloat SettingOption func NonNegativeFloatWithMaximum(maxValue float64) SettingOption func FloatWithMinimum(minValue float64) SettingOption // NEW func FloatWithMinimumOrZeroDisable(minValue float64) SettingOption // NEW var NonZeroFloat SettingOption // NEW var Fraction SettingOption // NEW var FractionUpperExclusive SettingOption // NEW func FloatInRange(minVal, maxVal float64) SettingOption // NEW func FloatInRangeUpperExclusive(minVal, maxVal float64) SettingOption // NEW func WithValidateInt(fn func(int64) error) SettingOption // NEW var NonNegativeInt SettingOption var PositiveInt SettingOption func NonNegativeIntWithMaximum(maxValue int64) SettingOption func IntWithMinimum(minValue int64) SettingOption // NEW func IntInRange(minVal, maxVal int64) SettingOption // NEW func IntInRangeOrZeroDisable(minVal, maxVal int64) SettingOption // NEW func WithValidateProto(fn func(*Values, protoutil.Message) error) SettingOption // NEW func WithValidateString(fn func(*Values, string) error) SettingOption // NEW func ByteSizeWithMinimum(minVal int64) SettingOption // NEW ``` Release note: None
- Loading branch information
Showing
161 changed files
with
1,295 additions
and
1,501 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.