storage

package
v0.0.0-...-7b4befc Latest Latest
Warning

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

Go to latest
Published: Apr 8, 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) FormatToMarkdown

func (s *Storage) FormatToMarkdown(provider string) (formatted string)

FormatToMarkdown Markdown formats the servers for the provider given and returns the resulting string.

func (*Storage) GetFilterChoices

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

func (*Storage) GetServerByName

func (s *Storage) GetServerByName(provider, name string) (
	server models.Server, ok bool)

GetServerByName returns the server for the given provider and server name. It returns `ok` as false if the server is not found. The returned server is also deep copied so it is safe for mutation and/or thread safe use.

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