From 0f5508013d776f8806a87957f80e74c7f74c72eb Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Mon, 20 May 2024 18:13:07 +0200 Subject: feat(config): print durations and URLs with human values --- internal/config/config.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'internal/config/config.go') diff --git a/internal/config/config.go b/internal/config/config.go index 939d7b1..3947d18 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -21,6 +21,10 @@ type URL struct { *url.URL } +func (u *URL) MarshalText() ([]byte, error) { + return []byte(u.URL.String()), nil +} + func (u *URL) UnmarshalText(text []byte) (err error) { u.URL, err = url.Parse(string(text)) @@ -35,6 +39,10 @@ type Duration struct { time.Duration } +func (d *Duration) MarshalText() ([]byte, error) { + return []byte(d.Duration.String()), nil +} + func (d *Duration) UnmarshalText(text []byte) (err error) { d.Duration, err = time.ParseDuration(string(text)) if err != nil { @@ -122,8 +130,8 @@ var defaultConfig = Config{ ImportPath: "nixos/release.nix", Attribute: "options", OutputPath: "share/doc/nixos", - FetchTimeout: 5 * time.Minute, - ImportTimeout: 15 * time.Minute, + FetchTimeout: Duration{5 * time.Minute}, + ImportTimeout: Duration{15 * time.Minute}, Repo: nixpkgs, }, "darwin": { @@ -137,8 +145,8 @@ var defaultConfig = Config{ ImportPath: "release.nix", Attribute: "options", OutputPath: "share/doc/darwin", - FetchTimeout: 5 * time.Minute, - ImportTimeout: 15 * time.Minute, + FetchTimeout: Duration{5 * time.Minute}, + ImportTimeout: Duration{15 * time.Minute}, Repo: Repository{ Type: "github", Owner: "LnL7", @@ -156,8 +164,8 @@ var defaultConfig = Config{ ImportPath: "default.nix", Attribute: "docs.json", OutputPath: "share/doc/home-manager", - FetchTimeout: 5 * time.Minute, - ImportTimeout: 15 * time.Minute, + FetchTimeout: Duration{5 * time.Minute}, + ImportTimeout: Duration{15 * time.Minute}, Repo: Repository{ Type: "github", Owner: "nix-community", @@ -172,8 +180,8 @@ var defaultConfig = Config{ Fetcher: ChannelNixpkgs, Channel: "nixos-unstable", OutputPath: "packages.json.br", - FetchTimeout: 5 * time.Minute, - ImportTimeout: 15 * time.Minute, + FetchTimeout: Duration{5 * time.Minute}, + ImportTimeout: Duration{15 * time.Minute}, Repo: nixpkgs, }, }, -- cgit 1.4.1