storage

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2023 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound      = errors.New("object not found in database")
	ErrAlreadyExists = errors.New("object already exists in the database")
)

Functions

This section is empty.

Types

type APIKey added in v1.0.0

type APIKey struct {
	ClientID   string    `msgpack:"client_id"`
	DerivedKey string    `msgpack:"derived_key"`
	Created    time.Time `msgpack:"created"`
	Modified   time.Time `msgpack:"modified"`
}

func (*APIKey) Key added in v1.0.0

func (m *APIKey) Key() ([]byte, error)

func (*APIKey) MarshalValue added in v1.0.0

func (m *APIKey) MarshalValue() ([]byte, error)

func (*APIKey) UnmarshalValue added in v1.0.0

func (m *APIKey) UnmarshalValue(data []byte) error

type ShortURL

type ShortURL struct {
	ID        uint64    `msgpack:"id"`
	URL       string    `msgpack:"url"`
	Expires   time.Time `msgpack:"expires"`
	Visits    uint64    `msgpack:"visits"`
	Created   time.Time `msgpack:"created"`
	Modified  time.Time `msgpack:"modified"`
	CreatedBy string    `msgpack:"created_by"`
}

func (*ShortURL) Key

func (m *ShortURL) Key() []byte

func (*ShortURL) MarshalValue

func (m *ShortURL) MarshalValue() ([]byte, error)

func (*ShortURL) UnmarshalValue

func (m *ShortURL) UnmarshalValue(data []byte) error

type Storage

type Storage interface {
	io.Closer
	Save(*ShortURL) error
	Load(uint64) (string, error)
	LoadInfo(uint64) (*ShortURL, error)
	Delete(uint64) error
	Register(*APIKey) error
	Retrieve(string) (*APIKey, error)
}

func Open

func Open(conf config.StorageConfig) (_ Storage, err error)

type Store

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

func (*Store) Close

func (s *Store) Close() error

func (*Store) Delete

func (s *Store) Delete(key uint64) error

func (*Store) Load

func (s *Store) Load(key uint64) (string, error)

func (*Store) LoadInfo

func (s *Store) LoadInfo(key uint64) (*ShortURL, error)

func (*Store) Register added in v1.0.0

func (s *Store) Register(obj *APIKey) error

func (*Store) Retrieve added in v1.0.0

func (s *Store) Retrieve(clientID string) (*APIKey, error)

func (*Store) Save

func (s *Store) Save(obj *ShortURL) error

Jump to

Keyboard shortcuts

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