about summary refs log tree commit diff stats
path: root/internal
diff options
context:
space:
mode:
authorAlan Pearce2024-05-20 18:13:07 +0200
committerAlan Pearce2024-05-20 18:13:07 +0200
commit0f5508013d776f8806a87957f80e74c7f74c72eb (patch)
tree1d7b9bbe1b296d08d2ca9e740dc546cccaf4e1df /internal
parentd0c2de9e762fb476b5cb53bb5129bf8af8cb9b45 (diff)
downloadsearchix-0f5508013d776f8806a87957f80e74c7f74c72eb.tar.lz
searchix-0f5508013d776f8806a87957f80e74c7f74c72eb.tar.zst
searchix-0f5508013d776f8806a87957f80e74c7f74c72eb.zip
feat(config): print durations and URLs with human values
Diffstat (limited to 'internal')
-rw-r--r--internal/config/config.go24
-rw-r--r--internal/config/source.go8
-rw-r--r--internal/fetcher/channel.go2
-rw-r--r--internal/fetcher/download.go2
-rw-r--r--internal/fetcher/nixpkgs-channel.go2
-rw-r--r--internal/importer/options.go2
-rw-r--r--internal/importer/package.go2
7 files changed, 23 insertions, 19 deletions
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,
 			},
 		},
diff --git a/internal/config/source.go b/internal/config/source.go
index 1fab61d..15b1aa0 100644
--- a/internal/config/source.go
+++ b/internal/config/source.go
@@ -1,9 +1,5 @@
 package config
 
-import (
-	"time"
-)
-
 type Source struct {
 	Name          string
 	Key           string
@@ -14,8 +10,8 @@ type Source struct {
 	URL           string
 	Attribute     string
 	ImportPath    string
-	FetchTimeout  time.Duration
-	ImportTimeout time.Duration
+	FetchTimeout  Duration
+	ImportTimeout Duration
 	OutputPath    string
 	Repo          Repository
 }
diff --git a/internal/fetcher/channel.go b/internal/fetcher/channel.go
index cadbab2..5dc84b4 100644
--- a/internal/fetcher/channel.go
+++ b/internal/fetcher/channel.go
@@ -25,7 +25,7 @@ type ChannelFetcher struct {
 func (i *ChannelFetcher) FetchIfNeeded(
 	parent context.Context,
 ) (f FetchedFiles, updated bool, err error) {
-	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout)
+	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout.Duration)
 	defer cancel()
 
 	dest := i.DataPath
diff --git a/internal/fetcher/download.go b/internal/fetcher/download.go
index 7657825..4165886 100644
--- a/internal/fetcher/download.go
+++ b/internal/fetcher/download.go
@@ -26,7 +26,7 @@ var files = map[string]string{
 func (i *DownloadFetcher) FetchIfNeeded(
 	parent context.Context,
 ) (f FetchedFiles, updated bool, err error) {
-	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout)
+	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout.Duration)
 	defer cancel()
 
 	root := i.DataPath
diff --git a/internal/fetcher/nixpkgs-channel.go b/internal/fetcher/nixpkgs-channel.go
index c135641..e36728c 100644
--- a/internal/fetcher/nixpkgs-channel.go
+++ b/internal/fetcher/nixpkgs-channel.go
@@ -32,7 +32,7 @@ var filesToFetch = map[string]string{
 func (i *NixpkgsChannelFetcher) FetchIfNeeded(
 	parent context.Context,
 ) (f FetchedFiles, updated bool, err error) {
-	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout)
+	ctx, cancel := context.WithTimeout(parent, i.Source.FetchTimeout.Duration)
 	defer cancel()
 
 	root := i.DataPath
diff --git a/internal/importer/options.go b/internal/importer/options.go
index 51a6eb4..8ce684c 100644
--- a/internal/importer/options.go
+++ b/internal/importer/options.go
@@ -88,7 +88,7 @@ func NewOptionProcessor(infile io.ReadCloser, source *config.Source) (*OptionIng
 }
 
 func (i *OptionIngester) Process(parent context.Context) (<-chan nix.Importable, <-chan error) {
-	ctx, cancel := context.WithTimeout(parent, i.source.ImportTimeout)
+	ctx, cancel := context.WithTimeout(parent, i.source.ImportTimeout.Duration)
 	results := make(chan nix.Importable)
 	errs := make(chan error)
 
diff --git a/internal/importer/package.go b/internal/importer/package.go
index c10a96d..dbc5854 100644
--- a/internal/importer/package.go
+++ b/internal/importer/package.go
@@ -105,7 +105,7 @@ func convertToLicense(in map[string]any) *nix.License {
 }
 
 func (i *PackageIngester) Process(parent context.Context) (<-chan nix.Importable, <-chan error) {
-	ctx, cancel := context.WithTimeout(parent, i.source.ImportTimeout)
+	ctx, cancel := context.WithTimeout(parent, i.source.ImportTimeout.Duration)
 	results := make(chan nix.Importable)
 	errs := make(chan error)