storage

package
v0.4.6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Callback added in v0.4.0

type Callback func(device *Device)

type Device

type Device struct {
	Owner         string    `json:"owner" gorm:"type:varchar(100);unique_index:key;primary_key"`
	OwnerName     string    `json:"owner_name"`
	OwnerEmail    string    `json:"owner_email"`
	OwnerProvider string    `json:"owner_provider"`
	Name          string    `json:"name" gorm:"type:varchar(100);unique_index:key;primary_key"`
	PublicKey     string    `json:"public_key" gorm:"unique_index"`
	Address       string    `json:"address"`
	CreatedAt     time.Time `json:"created_at" gorm:"column:created_at"`

	// metadata about the device during the current session
	LastHandshakeTime *time.Time `json:"last_handshake_time"`
	ReceiveBytes      int64      `json:"received_bytes"`
	TransmitBytes     int64      `json:"transmit_bytes"`
	Endpoint          string     `json:"endpoint"`
}

type GormLogger added in v0.3.0

type GormLogger struct{}

GormLogger is a custom logger for Gorm, making it use logrus.

func (*GormLogger) Print added in v0.3.0

func (*GormLogger) Print(v ...interface{})

Print handles log events from Gorm for the custom logger.

type InMemoryStorage

type InMemoryStorage struct {
	*InProcessWatcher
	// contains filtered or unexported fields
}

implements Storage interface

func NewMemoryStorage

func NewMemoryStorage() *InMemoryStorage

func (*InMemoryStorage) Close added in v0.3.0

func (s *InMemoryStorage) Close() error

func (*InMemoryStorage) Delete

func (s *InMemoryStorage) Delete(device *Device) error

func (*InMemoryStorage) Get

func (s *InMemoryStorage) Get(owner string, name string) (*Device, error)

func (*InMemoryStorage) GetByPublicKey added in v0.4.3

func (s *InMemoryStorage) GetByPublicKey(publicKey string) (*Device, error)

func (*InMemoryStorage) List

func (s *InMemoryStorage) List(username string) ([]*Device, error)

func (*InMemoryStorage) Open added in v0.3.0

func (s *InMemoryStorage) Open() error

func (*InMemoryStorage) Save

func (s *InMemoryStorage) Save(device *Device) error

type InProcessWatcher added in v0.4.0

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

func NewInProcessWatcher added in v0.4.0

func NewInProcessWatcher() *InProcessWatcher

func (*InProcessWatcher) EmitAdd added in v0.4.5

func (w *InProcessWatcher) EmitAdd(device *Device)

func (*InProcessWatcher) EmitDelete added in v0.4.5

func (w *InProcessWatcher) EmitDelete(device *Device)

func (*InProcessWatcher) OnAdd added in v0.4.0

func (w *InProcessWatcher) OnAdd(cb Callback)

func (*InProcessWatcher) OnDelete added in v0.4.0

func (w *InProcessWatcher) OnDelete(cb Callback)

func (*InProcessWatcher) OnReconnect added in v0.4.0

func (w *InProcessWatcher) OnReconnect(cb func())

type PgWatcher added in v0.4.0

type PgWatcher struct {
	*pgevents.Listener
}

func NewPgWatcher added in v0.4.0

func NewPgWatcher(connectionString string, table string) (*PgWatcher, error)

func (*PgWatcher) EmitAdd added in v0.4.5

func (w *PgWatcher) EmitAdd(device *Device)

func (*PgWatcher) EmitDelete added in v0.4.5

func (w *PgWatcher) EmitDelete(device *Device)

func (*PgWatcher) OnAdd added in v0.4.0

func (w *PgWatcher) OnAdd(cb Callback)

func (*PgWatcher) OnDelete added in v0.4.0

func (w *PgWatcher) OnDelete(cb Callback)

func (*PgWatcher) OnReconnect added in v0.4.0

func (w *PgWatcher) OnReconnect(cb func())

type SQLStorage added in v0.3.0

type SQLStorage struct {
	Watcher
	// contains filtered or unexported fields
}

implements Storage interface

func NewSqlStorage added in v0.3.0

func NewSqlStorage(u *url.URL) *SQLStorage

func (*SQLStorage) Close added in v0.3.0

func (s *SQLStorage) Close() error

func (*SQLStorage) Delete added in v0.3.0

func (s *SQLStorage) Delete(device *Device) error

func (*SQLStorage) Get added in v0.3.0

func (s *SQLStorage) Get(owner string, name string) (*Device, error)

func (*SQLStorage) GetByPublicKey added in v0.4.3

func (s *SQLStorage) GetByPublicKey(publicKey string) (*Device, error)

func (*SQLStorage) List added in v0.3.0

func (s *SQLStorage) List(username string) ([]*Device, error)

func (*SQLStorage) Open added in v0.3.0

func (s *SQLStorage) Open() error

func (*SQLStorage) Save added in v0.3.0

func (s *SQLStorage) Save(device *Device) error

type Storage

type Storage interface {
	Watcher
	Save(device *Device) error
	List(owner string) ([]*Device, error)
	Get(owner string, name string) (*Device, error)
	GetByPublicKey(publicKey string) (*Device, error)
	Delete(device *Device) error
	Close() error
	Open() error
}

func NewStorage added in v0.3.0

func NewStorage(uri string) (Storage, error)

type Watcher added in v0.4.0

type Watcher interface {
	OnAdd(cb Callback)
	OnDelete(cb Callback)
	OnReconnect(func())
	EmitAdd(device *Device)
	EmitDelete(device *Device)
}

Jump to

Keyboard shortcuts

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