storage

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package storage provides the implementation of the storage interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Storage

type Storage interface {
	// Insert adds a new TinyURL record to the storage.
	Insert(ctx context.Context, short uint64, longURL []byte) (*TinyURL, error)
	// GetByLongURL retrieves a TinyURL record by its original URL.
	GetByLongURL(ctx context.Context, long []byte) (*TinyURL, error)
	// GetByShortID retrieves a TinyURL record by its short ID.
	GetByShortID(ctx context.Context, short uint64) (*TinyURL, error)
	// Delete a short link by short id
	Delete(ctx context.Context, short uint64) error
	// Close closes the storage.
	Close() error
}

Storage is an interface that defines the methods that a storage system must implement.

func New

func New(db *gorm.DB) Storage

New creates a new storage instance.

type TinyURL

type TinyURL struct {
	gorm.Model
	LongURL []byte `gorm:"type:VARCHAR(500);uniqueIndex;not null" json:"long_url"` // The original URL.
	Short   uint64 `gorm:"type:BIGINT;uniqueIndex;not null" json:"short"`          // The shortened URL ID.
}

TinyURL represents a shortened URL record.

func (TinyURL) TableName

func (TinyURL) TableName() string

TableName returns the table name of the TinyURL model.

Jump to

Keyboard shortcuts

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