storage

package
v0.0.0-...-d3c2307 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: GPL-3.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

View Source
const (
	INTRODUCER  = "INTRODUCER"
	BRIDGE      = "BRIDGE"
	COUNTRYCODE = "COUNTRYCODE"
)

Variables

View Source
var AppName = "bitmask"

Functions

func InitAppStorage

func InitAppStorage() error

Init AppStorage initializes the global storage with the default storage directory

func InitAppStorageWith

func InitAppStorageWith(store Store)

InitAppStorage initializes the global storage with a given storage instance

Types

type CompareBridge

type CompareBridge func(bridge bridge.Bridge) bool

CompareBridge is a function type for the comparison of bridges

type CompareIntroducer

type CompareIntroducer func(introducer introducer.Introducer) bool

CompareIntroducer is a function type for the comparison of introducers

type DBStore

type DBStore struct {
	Store
	// contains filtered or unexported fields
}

func NewDBStore

func NewDBStore(path string) (*DBStore, error)

func (*DBStore) Clear

func (s *DBStore) Clear() error

func (*DBStore) Close

func (s *DBStore) Close() error

func (*DBStore) Contains

func (s *DBStore) Contains(key string) (bool, error)

func (*DBStore) GetBoolean

func (s *DBStore) GetBoolean(key string) bool

func (*DBStore) GetBooleanWithDefault

func (s *DBStore) GetBooleanWithDefault(key string, value bool) bool

func (*DBStore) GetByteArray

func (s *DBStore) GetByteArray(key string) []byte

func (*DBStore) GetByteArrayWithDefault

func (s *DBStore) GetByteArrayWithDefault(key string, value []byte) []byte

func (*DBStore) GetInt

func (s *DBStore) GetInt(key string) int

func (*DBStore) GetIntWithDefault

func (s *DBStore) GetIntWithDefault(key string, value int) int

func (*DBStore) GetLong

func (s *DBStore) GetLong(key string) int64

func (*DBStore) GetLongWithDefault

func (s *DBStore) GetLongWithDefault(key string, value int64) int64

func (*DBStore) GetString

func (s *DBStore) GetString(key string) string

func (*DBStore) GetStringWithDefault

func (s *DBStore) GetStringWithDefault(key string, value string) string

func (*DBStore) Open

func (s *DBStore) Open() error

func (*DBStore) Remove

func (s *DBStore) Remove(key string) error

func (*DBStore) SetBoolean

func (s *DBStore) SetBoolean(key string, value bool)

func (*DBStore) SetByteArray

func (s *DBStore) SetByteArray(key string, value []byte)

func (*DBStore) SetInt

func (s *DBStore) SetInt(key string, value int)

func (*DBStore) SetLong

func (s *DBStore) SetLong(key string, value int64)

func (*DBStore) SetString

func (s *DBStore) SetString(key string, value string)

Key-Value Setters

type Storage

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

func GetStorage

func GetStorage() (*Storage, error)

GetStorage returns an initialized storage instance if the global appStorage was initialized it has precedence

func NewStorage

func NewStorage(path string) (*Storage, error)

NewStorage initializes a new storage with a given path. `NewStorageWithDefaultDir` should be preferred to initialize a storage, since it will try to pick a default path.

func NewStorageWithDefaultDir

func NewStorageWithDefaultDir() (*Storage, error)

NewStoreageWithDefaultDir initializes a storage struct with a storm DB and looks up the correct default paths for Linux, MacOS and Windows. Don't call this method in context of mobile app development

func NewStorageWithStore

func NewStorageWithStore(store Store) *Storage

NewStorageWithStore initializes the storage struct with a custom store. This can be used to implement custom storage adapters e.g. for different database types

func (*Storage) AddIntroducer

func (s *Storage) AddIntroducer(intro *introducer.Introducer) error

Add new introducer to storage. Before, delete all existing introducers with the same fqdn

func (*Storage) Close

func (s *Storage) Close()

Close closes the db connection

func (*Storage) DeleteBridge

func (s *Storage) DeleteBridge(name string) error

DeleteBridge accepts a name and an ID. If you want to delete by name, pass 0 as the ID; if you want to delete by ID, pass the empty string as name.

func (*Storage) DeleteIntroducer

func (s *Storage) DeleteIntroducer(fqdn string) error

DeleteIntroducer deletes all introducers for a given fqdn.

func (*Storage) GetBridgeByName

func (s *Storage) GetBridgeByName(name string) (*bridge.Bridge, error)

GetBridgeByName will return the Bridge with the given Name, if found, and an error.

func (*Storage) GetBridgesByLocation

func (s *Storage) GetBridgesByLocation(location string) ([]bridge.Bridge, error)

GetBridgesByLocation will return all Bridges with the given Location, if found, and an error.

func (*Storage) GetBridgesByType

func (s *Storage) GetBridgesByType(bridgeType string) ([]bridge.Bridge, error)

GetBridgesByType will return all Bridges with the given Type, if found, and an error.

func (*Storage) GetFallbackCountryCode

func (s *Storage) GetFallbackCountryCode() string

func (*Storage) GetIntroducerByFQDN

func (s *Storage) GetIntroducerByFQDN(fqdn string) (*introducer.Introducer, error)

GetIntroducerByFQDN returns the first introducer for a given fqdn.

func (*Storage) ListBridges

func (s *Storage) ListBridges() ([]bridge.Bridge, error)

ListBridges returns an array of all the bridges.

func (*Storage) ListIntroducers

func (s *Storage) ListIntroducers() ([]introducer.Introducer, error)

ListIntroducers returns an array of all introducers

func (*Storage) NewBridge

func (s *Storage) NewBridge(name, bridgeType, location, raw string) error

NewBridge creates a new Bridge from the passed parameters.

func (*Storage) SaveFallbackCountryCode

func (s *Storage) SaveFallbackCountryCode(cc string)

type Store

type Store interface {
	// Key-Value Getters
	GetString(key string) string
	GetStringWithDefault(key string, value string) string
	GetBoolean(key string) bool
	GetBooleanWithDefault(key string, value bool) bool
	GetInt(key string) int
	GetIntWithDefault(key string, value int) int
	GetLong(key string) int64
	GetLongWithDefault(key string, value int64) int64
	GetByteArray(key string) []byte
	GetByteArrayWithDefault(key string, value []byte) []byte

	// Key-Value Setters
	SetString(key string, value string)
	SetBoolean(key string, value bool)
	SetInt(key string, value int)
	SetLong(key string, value int64)
	SetByteArray(key string, value []byte)

	Open() error
	Close() error
	Contains(key string) (bool, error)
	Remove(key string) error
	Clear() error
}

Jump to

Keyboard shortcuts

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