repo

package
v0.0.0-...-396892a Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MongoConfig

type MongoConfig struct {
	Addr       string
	User, Pass string
	Database   string
	Collection string
}

MongoConfig contains mongodb connection options.

type MongoRepository

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

MongoRepository is a mongodb storage.

func NewMongoRepository

func NewMongoRepository(ctx context.Context, cfg MongoConfig) (*MongoRepository, error)

NewMongoRepository establishes a new mongodb connection and creates a new repository with mongodb collection.

func (*MongoRepository) Delete

func (r *MongoRepository) Delete(ctx context.Context, short string) error

Delete deletes an URL by short.

func (*MongoRepository) Get

func (r *MongoRepository) Get(ctx context.Context, short string) (*model.URL, error)

Get returns an URL by short.

func (*MongoRepository) Store

func (r *MongoRepository) Store(ctx context.Context, short, origin string) error

Store stores an URL.

func (*MongoRepository) Update

func (r *MongoRepository) Update(ctx context.Context, short string, viewsDelta int64) error

Update updates views count.

type Repository

type Repository interface {
	Store(ctx context.Context, short, origin string) error
	Get(ctx context.Context, short string) (*model.URL, error)
	Update(ctx context.Context, short string, viewsDelta int64) error
	Delete(ctx context.Context, short string) error
}

Repository represents a repository.

Jump to

Keyboard shortcuts

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