feat: add custom Duration type for config values#989
Open
tmchow wants to merge 1 commit intogetprobo:mainfrom
Open
feat: add custom Duration type for config values#989tmchow wants to merge 1 commit intogetprobo:mainfrom
tmchow wants to merge 1 commit intogetprobo:mainfrom
Conversation
Create a Duration type in pkg/duration that wraps time.Duration and unmarshals from both integer seconds (backward compatible) and Go duration strings like "30s" or "1h". Replace raw int fields in WebhookConfig and SlackConfig with the new type. Remove manual time.Duration multiplication at use sites. Closes getprobo#234
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.
Adds a
Durationtype inpkg/durationthat wrapstime.Durationand unmarshals from both integer seconds (backward compatible) and Go duration strings like"30s","5m","1h".Replaces the raw
intfields inWebhookConfigandSlackConfigwith the new type. Removes manualtime.Duration(x) * time.Secondconversions at use sites inprobod.go.The new type handles backward compatibility: existing configs that use integer seconds (e.g.
86400) continue to work. New configs can use readable strings (e.g."24h").Changes
pkg/duration/duration.go:Durationtype withMarshalJSON,UnmarshalJSON,String()pkg/duration/duration_test.go: tests for int, string, roundtrip, and invalid inputspkg/probod/notifications_config.go:WebhookConfigfields updatedpkg/probod/slack_config.go:SlackConfig.SenderIntervalupdatedpkg/probod/probod.go: removed manual second conversionspkg/bootstrap/builder.go: env parsing handles both int and string durationspkg/bootstrap/builder_test.go: updated assertionsCloses #234
Summary by cubic
Introduce a custom
Durationtype for config values, allowing both integer seconds and Go-style duration strings, and use it for Slack/Webhook intervals and TTL. This keeps existing configs working, simplifies parsing, and removes manual time conversions. Closes #234.New Features
pkg/durationwith JSON marshal/unmarshal supporting ints (seconds) and strings like "30s", "5m", "1h".intwithduration.DurationinSlackConfig.SenderInterval,WebhookConfig.SenderInterval, andWebhookConfig.CacheTTL.pkg/bootstrap/builderto parse env vars as either ints or duration strings; set defaults to60s,5s, and24h.time.Secondmultiplications inprobod.go; usetime.Duration(cfgValue)directly.Migration
Written for commit 9735795. Summary will update on new commits.