storage

package
v0.0.0-...-ddd9f4d Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2024 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoServerFound = errors.New("no server found")

Functions

This section is empty.

Types

type Infoer

type Infoer interface {
	Info(s string)
}

type Storage

type Storage struct {
	// contains filtered or unexported fields
}

func New

func New(logger Infoer, filepath string) (storage *Storage, err error)

New creates a new storage and reads the servers from the embedded servers file and the file on disk. Passing an empty filepath disables writing servers to a file.

func (*Storage) FilterServers

func (s *Storage) FilterServers(provider string, selection settings.ServerSelection) (
	servers []models.Server, err error,
)

FilterServers filter servers for the given provider and according to the given selection. The filtered servers are deep copied so they are safe for mutation by the caller.

func (*Storage) FlushToFile

func (s *Storage) FlushToFile(path string) error

FlushToFile flushes the merged servers data to the file specified by path, as indented JSON.

func (*Storage) Format

func (s *Storage) Format(provider, format string) (formatted string, err error)

Format formats the servers for the provider using the format given and returns the resulting string.

func (*Storage) GetFilterChoices

func (s *Storage) GetFilterChoices(provider string) models.FilterChoices

func (*Storage) GetServersCount

func (s *Storage) GetServersCount(provider string) (count int)

GetServersCount returns the number of servers for the provider given.

func (*Storage) ServersAreEqual

func (s *Storage) ServersAreEqual(provider string, servers []models.Server) (equal bool)

GetServersCount returns the number of servers for the provider given.

func (*Storage) SetServers

func (s *Storage) SetServers(provider string, servers []models.Server) (err error)

SetServers sets the given servers for the given provider in the storage in-memory map and saves all the servers to file. Note the servers given are not copied so the caller must NOT MUTATE them after calling this method.

Jump to

Keyboard shortcuts

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