db

package
v2.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB interface {
	//Get returns the *URL with the given id, or an error if one occurred.
	//If a *URL with the given id doesn't exist, url will be nil
	Get(id string) (url *URL, err error)

	//Put saves the given url in the database for the given user, returning the id, or an error
	//if one occurred.
	Put(url *URL, user string) (id string, err error)

	//Update updates the *URL with the given id or returns an error if one occurred
	Update(id string, url *URL) error

	//Delete deletes the *URL with the given id or returns an error if one occurred
	Delete(id string) error

	//View returns the url with the given id, or an error if one occurred.
	//If a url with the given id doesn't exist, url will be empty.
	//View increments the view counter for the URL and should be used
	//by clients wanting to resolve the shortened URL.
	View(id string) (url string, err error)

	//URLs returns the URLs for the given user or all URLs if user is empty
	//or an error if one occurred
	URLs(user string) ([]*URL, error)
}

DB represents a URL shortening database

type URL

type URL struct {
	ID           string     `json:"id"`
	User         string     `json:"user"`
	URL          string     `json:"url"`
	Views        uint64     `json:"views"`
	Expires      *time.Time `json:"expires"`
	LastModified *time.Time `json:"last_modified"`
}

URL represents a shortened URL

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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