index

package
v0.0.0-...-30fe120 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package index implements all the logic for handling indexes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Configs []ConfigEntry `yaml:"configs"`
}

Config aggregates the info about ConfigEntries.

func NewConfig

func NewConfig(path string) (*Config, error)

NewConfig loads an index config from a file.

func (*Config) Add

func (c *Config) Add(entry ConfigEntry)

Add adds a new config to Config.

func (*Config) Get

func (c *Config) Get(name string) (*ConfigEntry, error)

Get returns a pointer to an entry in a Config.

func (*Config) Remove

func (c *Config) Remove(name string) error

Remove removes a config by name from an Config.

func (*Config) Write

func (c *Config) Write(path string) error

Write writes an Config to disk.

type ConfigEntry

type ConfigEntry struct {
	AddedTimestamp string `yaml:"added_timestamp"`
	// CaFile                string `yaml:"caFile"`
	// CertFile              string `yaml:"certFile"`
	// InsecureSkipTLSVerify string `yaml:"insecure_skip_tls_verify"`
	// KeyFile               string `yaml:"keyFile"`
	Name string `yaml:"name"`
	// PassCredentialsAll    string `yaml:"pass_credentials_all"`
	// Password              string `yaml:"password"`
	UpdatedTimestamp string `yaml:"updated_timestamp"`
	URL              string `yaml:"url"`
}

ConfigEntry contains information about one of the index that were cached locally. TODO: add support for all the other fields.

type Entry

type Entry struct {
	// Mandatory fields
	Name       string `yaml:"name"`
	Type       string `yaml:"type"`
	Registry   string `yaml:"registry"`
	Repository string `yaml:"repository"`
	// Optional fields
	Description string   `yaml:"description"`
	Home        string   `yaml:"home"`
	Keywords    []string `yaml:"keywords"`
	License     string   `yaml:"license"`
	Maintainers []struct {
		Email string `yaml:"email"`
		Name  string `yaml:"name"`
	} `yaml:"maintainers"`
	Sources []string `yaml:"sources"`
}

Entry describes an entry of the index stored remotely and cached locally.

type Index

type Index struct {
	Name    string
	Entries []*Entry
	// contains filtered or unexported fields
}

Index represents an index.

func Fetch

func Fetch(ctx context.Context, url, name string) (*Index, error)

Fetch retrieves a remote index using its URL.

func New

func New(name string) *Index

New returns a new empty Index.

func (*Index) EntryByName

func (i *Index) EntryByName(name string) (*Entry, bool)

EntryByName returns a Entry by passing its name.

func (*Index) Normalize

func (i *Index) Normalize() error

Normalize the index to the canonical form (i.e., entries sorted by name, lexically byte-wise in ascending order).

Since only one possible representation of a normalized index exists, a digest of a normalized index is suitable for integrity checking or similar purposes. Return an error if the index is not in a consistent state.

func (*Index) Read

func (i *Index) Read(path string) error

Read reads entries from a file.

func (*Index) Remove

func (i *Index) Remove(entry *Entry) error

Remove removes an entry from the Index.

func (*Index) SearchByKeywords

func (i *Index) SearchByKeywords(minScore float64, keywords ...string) []*Entry

SearchByKeywords search for entries matching the given keywords in MergedIndexes. minScore is the minimum score to consider a match between a name of an artifact and a keyword. if minScore is not reached, we fallback to a simple partial matching on keywords.

func (*Index) Upsert

func (i *Index) Upsert(entry *Entry)

Upsert adds a new entry to the Index or updates an existing one.

func (*Index) Write

func (i *Index) Write(path string) error

Write writes entries to a file.

type MergedIndexes

type MergedIndexes struct {
	Index
	// contains filtered or unexported fields
}

MergedIndexes is used to aggregate all indexes and perform search operations.

func NewMergedIndexes

func NewMergedIndexes() *MergedIndexes

NewMergedIndexes initializes a MergedIndex.

func (*MergedIndexes) IndexByEntry

func (m *MergedIndexes) IndexByEntry(entry *Entry) *Index

IndexByEntry is used to retrieve the original index from an entry in MergedIndexes.

func (*MergedIndexes) Merge

func (m *MergedIndexes) Merge(indexes ...*Index)

Merge creates a new index by merging all the indexes that are passed. Orders matters. Be sure to pass an ordered list of indexes. For our use case, sort by added time.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL