session

package
v0.26.1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2021 License: MIT Imports: 7 Imported by: 81

Documentation

Overview

Package session implements session storage.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("session storage: not found")

ErrNotFound means that session is not found in storage.

Functions

This section is empty.

Types

type Data

type Data struct {
	Config    tg.Config
	DC        int
	Addr      string
	AuthKey   []byte
	AuthKeyID []byte
	Salt      int64
}

Data of session.

type FileStorage

type FileStorage struct {
	Path string
}

FileStorage implements SessionStorage for file system as file stored in Path.

func (*FileStorage) LoadSession

func (f *FileStorage) LoadSession(_ context.Context) ([]byte, error)

LoadSession loads session from file.

func (*FileStorage) StoreSession

func (f *FileStorage) StoreSession(_ context.Context, data []byte) error

StoreSession stores session to file.

type Loader

type Loader struct {
	Storage Storage
}

Loader wraps Storage implementing Data (un-)marshaling.

func (*Loader) Load

func (l *Loader) Load(ctx context.Context) (*Data, error)

Load loads Data from Storage.

func (*Loader) Save

func (l *Loader) Save(ctx context.Context, data *Data) error

Save saves Data to Storage.

type Storage

type Storage interface {
	LoadSession(ctx context.Context) ([]byte, error)
	StoreSession(ctx context.Context, data []byte) error
}

Storage is secure persistent storage for client session.

NB: Implementation security is important, attacker can use not only for connecting as authenticated user or bot, but even decrypting previous messages in some situations.

type StorageMemory

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

StorageMemory implements in-memory session storage. Goroutine-safe.

func (*StorageMemory) LoadSession

func (s *StorageMemory) LoadSession(ctx context.Context) ([]byte, error)

LoadSession loads session from memory.

func (*StorageMemory) StoreSession

func (s *StorageMemory) StoreSession(ctx context.Context, data []byte) error

StoreSession stores session to memory.

Jump to

Keyboard shortcuts

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