links

package
v0.0.0-...-47020db Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddSlugToLink(l *Link) error

AddSlugToLink populates Link object with slug derived from ID

func AppendPrefixToURL

func AppendPrefixToURL(prefix string, url string) string

AppendPrefixToURL Appends specified prefix to the beginning of the URL

func CheckURLLength

func CheckURLLength(sourceURL string, minLen int) (bool, error)

CheckURLLength checks if specified URL length is not less than minLen

func IDToURL

func IDToURL(id string) (string, error)

IDToURL converts provided string containing hex to base62

func NewHandler

func NewHandler(logger logging.Logger, storage Storage, linkTTL time.Duration, blackListedURls []string) handlers.Handler

NewHandler Return pointer to links handler

func StringInSlice

func StringInSlice(s string, arr []string) bool

StringInSlice checks if string s is in the array of strings arr

func URLHostIsUp

func URLHostIsUp(sourceURL string) (bool, error)

URLHostIsUp checks if specified URL is up and returned status < 500

func URLIsValid

func URLIsValid(sourceURL string, blackListedURls []string) (bool, error)

URLIsValid checks if specified URL can be parsed and is absolute

func URLToID

func URLToID(b62 string) (string, error)

URLToID converts provided base62 string to hex

Types

type CreateLinkDTO

type CreateLinkDTO struct {
	Source string `json:"source"`
}

CreateLinkDTO Data Tansfer Object for Link creation

type Link struct {
	ID              string        `json:"id,omitempty" bson:"_id,omitempty"`
	Source          string        `json:"source" bson:"source"`
	Views           uint          `json:"views,omitempty" bson:"views"`
	ExpireAt        time.Time     `json:"expire_at,omitempty" bson:"expire_at"`
	CreatedAt       time.Time     `json:"created_at,omitempty" bson:"created_at"`
	TTLMilliseconds time.Duration `json:"ttl_milliseconds,omitempty" bson:"ttl"`
	Slug            string        `json:"slug,omitempty" bson:"slug,omitempty"`
}

Link model

type Service

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

Service object

func (*Service) CheckLinkService

func (s *Service) CheckLinkService(url string) *URLCheckException

CheckLinkService for CheckLinkHandler

func (*Service) CreateService

func (s *Service) CreateService(ctx context.Context, dto CreateLinkDTO) (l Link, err error)

CreateService for CreateHandler

func (*Service) GetLinkByIDService

func (s *Service) GetLinkByIDService(ctx context.Context, id string) (l Link, err error)

GetLinkByIDService for GetLinkByIDHandler

type Storage

type Storage interface {
	Create(ctx context.Context, link Link) (string, bool, error)
	FindOne(ctx context.Context, id string) (Link, error)
	FindOneBySource(ctx context.Context, source string) (Link, error)
	Delete(ctx context.Context, id string) error
}

Storage interface

type URLCheckException

type URLCheckException struct {
	HostIsUp   bool  `json:"host_is_up"`
	URLIsValid bool  `json:"url_is_valid"`
	Err        error `json:"-"`
}

URLCheckException describes a result of a failed URL check

func (*URLCheckException) Error

func (e *URLCheckException) Error() string

func (*URLCheckException) JSON

func (e *URLCheckException) JSON() ([]byte, error)
JSON Marshal URLCheckException

{"host_is_up":bool,"url_is_valid":bool}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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