Documentation ¶
Index ¶
- func AddSlugToLink(l *Link) error
- func AppendPrefixToURL(prefix string, url string) string
- func CheckURLLength(sourceURL string, minLen int) (bool, error)
- func IDToURL(id string) (string, error)
- func NewHandler(logger logging.Logger, storage Storage, linkTTL time.Duration, ...) handlers.Handler
- func StringInSlice(s string, arr []string) bool
- func URLHostIsUp(sourceURL string) (bool, error)
- func URLIsValid(sourceURL string, blackListedURls []string) (bool, error)
- func URLToID(b62 string) (string, error)
- type CreateLinkDTO
- type Link
- type Service
- type Storage
- type URLCheckException
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddSlugToLink ¶
AddSlugToLink populates Link object with slug derived from ID
func AppendPrefixToURL ¶
AppendPrefixToURL Appends specified prefix to the beginning of the URL
func CheckURLLength ¶
CheckURLLength checks if specified URL length is not less than minLen
func NewHandler ¶
func NewHandler(logger logging.Logger, storage Storage, linkTTL time.Duration, blackListedURls []string) handlers.Handler
NewHandler Return pointer to links handler
func StringInSlice ¶
StringInSlice checks if string s is in the array of strings arr
func URLHostIsUp ¶
URLHostIsUp checks if specified URL is up and returned status < 500
func URLIsValid ¶
URLIsValid checks if specified URL can be parsed and is absolute
Types ¶
type CreateLinkDTO ¶
type CreateLinkDTO struct {
Source string `json:"source"`
}
CreateLinkDTO Data Tansfer Object for Link creation
type Link ¶
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 ¶
CreateService for CreateHandler
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}