Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Chandler <wchandler@gitlab.com>2022-08-20 16:15:22 +0300
committerWill Chandler <wchandler@gitlab.com>2022-08-20 16:15:22 +0300
commit28b52c3b64fb857de6b1c62af662fe54249fa225 (patch)
treea637cef25392bedd1651349b64fb8ec922fbc412 /internal/helper/duration/duration.go
parent109499970cae4fa648d9c0119bb708f0dd65f1d4 (diff)
parent72e1c78e920a917ae96a25271173740e6557888e (diff)
Merge branch 'renovate/github.com-pelletier-go-toml-2.x' into 'master'
go: Update module github.com/pelletier/go-toml to v2 See merge request gitlab-org/gitaly!4652
Diffstat (limited to 'internal/helper/duration/duration.go')
-rw-r--r--internal/helper/duration/duration.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/internal/helper/duration/duration.go b/internal/helper/duration/duration.go
new file mode 100644
index 000000000..5d1e5b87d
--- /dev/null
+++ b/internal/helper/duration/duration.go
@@ -0,0 +1,28 @@
+package duration
+
+import "time"
+
+// Duration is a trick to let our TOML library parse durations from strings.
+type Duration time.Duration
+
+// Duration converts the duration.Duration to a time.Duration
+func (d *Duration) Duration() time.Duration {
+ if d != nil {
+ return time.Duration(*d)
+ }
+ return 0
+}
+
+// UnmarshalText implements the encoding.TextUnmarshaler interface
+func (d *Duration) UnmarshalText(text []byte) error {
+ td, err := time.ParseDuration(string(text))
+ if err == nil {
+ *d = Duration(td)
+ }
+ return err
+}
+
+// MarshalText implements the encoding.TextMarshaler interface
+func (d Duration) MarshalText() ([]byte, error) {
+ return []byte(time.Duration(d).String()), nil
+}