storage

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2021 License: MIT Imports: 7 Imported by: 16

Documentation

Overview

Package storage contains common structures for iterating over peer storage.

Index

Constants

View Source
const LatestVersion = 1

LatestVersion is a latest supported version of data.

Variables

View Source
var ErrPeerNotFound = xerrors.New("peer not found")

ErrPeerNotFound is a special error to return when peer not found.

Functions

This section is empty.

Types

type Key

type Key struct {
	Kind peer.Kind
	ID   int
}

Key is unique key of peer object.

func KeyFromPeer

func KeyFromPeer(p Peer) Key

KeyFromPeer creates key from peer.

func (Key) Bytes

func (k Key) Bytes(r []byte) []byte

Bytes returns bytes representation of key.

func (*Key) Parse

func (k *Key) Parse(r []byte) error

Parse parses bytes representation from given slice.

type Peer

type Peer struct {
	Version   int
	Key       peer.DialogKey
	CreatedAt int64
	User      *tg.User    `json:",omitempty"`
	Chat      *tg.Chat    `json:",omitempty"`
	Channel   *tg.Channel `json:",omitempty"`
}

Peer is abstraction for peer object.

func (Peer) AsInputChannel

func (p Peer) AsInputChannel() (*tg.InputChannel, bool)

AsInputChannel tries to convert peer to *tg.InputChannel.

func (Peer) AsInputPeer

func (p Peer) AsInputPeer() tg.InputPeerClass

AsInputPeer tries to convert peer to tg.InputPeerClass.

func (Peer) AsInputUser

func (p Peer) AsInputUser() (*tg.InputUser, bool)

AsInputUser tries to convert peer to *tg.InputUser.

func (*Peer) FromInputPeer

func (p *Peer) FromInputPeer(input tg.InputPeerClass) error

FromInputPeer fills Peer object using given tg.InputPeerClass.

type PeerStorage

type PeerStorage interface {
	// Add adds given peer to the storage.
	Add(ctx context.Context, p Peer) error
	// Find finds peer using given key.
	// If peer not found, it returns ErrPeerNotFound error.
	Find(ctx context.Context, key Key) (Peer, error)

	// Assign adds given peer to the storage and associates it to the given key.
	Assign(ctx context.Context, key string, p Peer) error
	// Resolve finds peer using associated key.
	// If peer not found, it returns ErrPeerNotFound error.
	Resolve(ctx context.Context, key string) (Peer, error)
}

PeerStorage is abstraction for peer storage.

type ResolverCache

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

ResolverCache is a peer.Resolver cache implemented using peer storage.

func NewResolverCache

func NewResolverCache(next peer.Resolver, storage PeerStorage) ResolverCache

NewResolverCache creates new ResolverCache.

func (ResolverCache) ResolveDomain

func (r ResolverCache) ResolveDomain(ctx context.Context, domain string) (tg.InputPeerClass, error)

ResolveDomain implements peer.Resolver

func (ResolverCache) ResolvePhone

func (r ResolverCache) ResolvePhone(ctx context.Context, phone string) (tg.InputPeerClass, error)

ResolvePhone implements peer.Resolver

Jump to

Keyboard shortcuts

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