about summary refs log tree commit diff stats
path: root/internal/nix
diff options
context:
space:
mode:
authorAlan Pearce2024-05-16 20:22:42 +0200
committerAlan Pearce2024-05-16 20:31:03 +0200
commitc51ca7c62e08f43ef9974af35886d30ce54a1f22 (patch)
tree6779f521c289d1750ceb35b57fbb0d3acad20385 /internal/nix
parent0ef52f2f82c62694c5420f7f6c82fb8c45900d1d (diff)
downloadsearchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.lz
searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.tar.zst
searchix-c51ca7c62e08f43ef9974af35886d30ce54a1f22.zip
refactor: use interface to unify Options and Packages
Diffstat (limited to 'internal/nix')
-rw-r--r--internal/nix/importable.go11
-rw-r--r--internal/nix/option.go37
-rw-r--r--internal/nix/package.go41
3 files changed, 89 insertions, 0 deletions
diff --git a/internal/nix/importable.go b/internal/nix/importable.go
new file mode 100644
index 0000000..309ec5f
--- /dev/null
+++ b/internal/nix/importable.go
@@ -0,0 +1,11 @@
+package nix
+
+type Importable interface {
+	BleveType() string
+	GetName() string
+	GetSource() string
+}
+
+func GetKey(i Importable) string {
+	return i.BleveType() + "/" + i.GetSource() + "/" + i.GetName()
+}
diff --git a/internal/nix/option.go b/internal/nix/option.go
new file mode 100644
index 0000000..c1cc4c3
--- /dev/null
+++ b/internal/nix/option.go
@@ -0,0 +1,37 @@
+package nix
+
+type Markdown string
+
+type Value struct {
+	Text     string   `json:",omitempty"`
+	Markdown Markdown `json:",omitempty"`
+}
+
+type Link struct {
+	Name string
+	URL  string
+}
+
+type Option struct {
+	Name            string
+	Source          string
+	Declarations    []Link
+	Default         *Value `json:",omitempty"`
+	Description     Markdown
+	Example         *Value `json:",omitempty"`
+	Loc             []string
+	RelatedPackages Markdown `json:",omitempty"`
+	Type            string
+}
+
+func (Option) BleveType() string {
+	return "option"
+}
+
+func (p Option) GetName() string {
+	return p.Name
+}
+
+func (p Option) GetSource() string {
+	return p.Source
+}
diff --git a/internal/nix/package.go b/internal/nix/package.go
new file mode 100644
index 0000000..4158d1f
--- /dev/null
+++ b/internal/nix/package.go
@@ -0,0 +1,41 @@
+package nix
+
+type Package struct {
+	Name            string
+	Source          string
+	Broken          bool
+	Definition      string
+	Description     string
+	Homepages       []string
+	Licenses        []License
+	LongDescription string
+	MainProgram     string
+	Maintainers     []Maintainer
+	Platforms       []string
+	Version         string
+}
+
+type License struct {
+	FullName    string
+	Name        string
+	SPDXId      string
+	URL         string
+	AppendixURL string
+}
+
+type Maintainer struct {
+	Github string
+	Name   string
+}
+
+func (Package) BleveType() string {
+	return "package"
+}
+
+func (p Package) GetName() string {
+	return p.Name
+}
+
+func (p Package) GetSource() string {
+	return p.Source
+}