all repos — searchix @ 9327a79febcce1056f2935918a947adb6f80a5c8

Search engine for NixOS, nix-darwin, home-manager and NUR users

internal/nix/importable.go (view raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package nix

import (
	"encoding/gob"

	"alin.ovh/searchix/internal/config"
)

type Importable interface {
	BleveType() string
	GetName() string
	GetSource() string
}

func GetKey(i Importable) string {
	return i.BleveType() + "/" + i.GetSource() + "/" + i.GetName()
}

func MakeKey(source *config.Source, id string) string {
	return source.Importer.Singular() + "/" + source.Key + "/" + id
}

func ToGenericChannel[I Importable](in <-chan I) <-chan Importable {
	out := make(chan Importable)
	go func() {
		for i := range in {
			out <- i
		}
		close(out)
	}()

	return out
}

func init() {
	gob.Register(Option{})
	gob.Register(Package{})
}