url

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2022 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Collection = "urls"
)

Collection is a name of the MongoDB collection for URLs.

Variables

View Source
var (
	// ErrKeyNotFound indicates that given key does not exist on database.
	ErrKeyNotFound = errors.New("given key does not exist or expired")
	// ErrDuplicateKey indicates that given key is exists on database.
	ErrDuplicateKey = errors.New("given key is exist")
)

Functions

This section is empty.

Types

type MemoryURL

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

func NewMemoryURL

func NewMemoryURL() *MemoryURL

func (*MemoryURL) Count

func (m *MemoryURL) Count(ctx context.Context, key string) (int, error)

func (*MemoryURL) Get

func (m *MemoryURL) Get(ctx context.Context, key string) (string, error)

func (*MemoryURL) Inc

func (m *MemoryURL) Inc(ctx context.Context, key string) error

func (*MemoryURL) Set

func (m *MemoryURL) Set(ctx context.Context, key string, url string, expire *time.Time, count int) (string, error)

type MongoURL

type MongoURL struct {
	DB      *mongo.Database
	Tracer  trace.Tracer
	Metrics Usage
}

MongoURL communicate with url collections in MongoDB.

func NewMongoURL

func NewMongoURL(db *mongo.Database, tracer trace.Tracer) *MongoURL

NewMongoURL creates new URL store.

func (*MongoURL) Count

func (s *MongoURL) Count(ctx context.Context, key string) (int, error)

Count retrieves number of access for the url of the given key if it exists.

func (*MongoURL) Get

func (s *MongoURL) Get(ctx context.Context, key string) (string, error)

Get retrieves url of the given key if it exists.

func (*MongoURL) Inc

func (s *MongoURL) Inc(ctx context.Context, key string) error

Inc increments counter of url record by one.

func (*MongoURL) Set

func (s *MongoURL) Set(ctx context.Context, key, url string, expire *time.Time, count int) (string, error)

Set saves given url with a given key in database. if key is null it generates a random key and returns it.

type URL

type URL interface {
	Inc(ctx context.Context, key string) error
	Set(ctx context.Context, key, url string, expire *time.Time, count int) (string, error)
	Get(ctx context.Context, key string) (string, error)
	Count(ctx context.Context, key string) (int, error)
}

URL stores and retrieves urls.

type Usage

type Usage struct {
	InsertedCounter prometheus.Counter
	FetchedCounter  prometheus.Counter
}

Usage contains metrics to meter database insert/retrieve.

func NewUsage

func NewUsage(name string) Usage

Jump to

Keyboard shortcuts

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