data

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 7, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrURLNotFound error = errors.New("URL not found")

ErrURLNotFound Url not found in urlList

Functions

func ValidateURL

func ValidateURL(longURL string) bool

ValidateURL checks if given URL is valid

Types

type URL

type URL struct {
	ID          int    `json:"id" validate:"isdefault"`
	OriginalURL string `json:"url" validate:"required"`
	ShortURL    string `json:"shortened_url" validate:"isdefault"`
}

URL struct for storing url details

func (*URL) FromJSON

func (u *URL) FromJSON(r io.Reader) error

FromJSON extracts URL struct from JSON

func (*URL) Validate

func (u *URL) Validate() error

Validate checks if URL struct valid

type Urls

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

Urls is a collection of URL

func (*Urls) AddURL

func (urlList *Urls) AddURL(u *URL)

AddURL adds a new URL to urlList

func (*Urls) GetURLByLong

func (urlList *Urls) GetURLByLong(longURL string) (*URL, error)

GetURLByLong returns the URL struct with given original url from urlList returns ErrUrlNotFOund if url does not exists in urlList

func (*Urls) GetURLByShort

func (urlList *Urls) GetURLByShort(shortURL string) (*URL, error)

GetURLByShort return the URL struct with given shortened URL from urlList

func (*Urls) Init

func (urlList *Urls) Init(data []*URL)

Init initialises an urlList with specified data

func (*Urls) ShortURL

func (urlList *Urls) ShortURL(longURL string) string

ShortURL generates a random string with length 8 that is not present in database yet

Jump to

Keyboard shortcuts

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