services

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ShortlinkService

type ShortlinkService struct {
	DB     *sqlx.DB
	Logger *log.Logger
}

ShortlinkService manages shortlinks.

func (*ShortlinkService) GenerateSlug

func (ss *ShortlinkService) GenerateSlug() (string, error)

GenerateSlug generates a random URL-encoded shortlink slug, ensuring uniqueness with DB.

func (*ShortlinkService) GetBySlug

func (ss *ShortlinkService) GetBySlug(slug string) (*entities.Shortlink, error)

GetBySlug retrieves the main parts of a shortlink by its slug.

func (*ShortlinkService) HashPassword

func (ss *ShortlinkService) HashPassword(plaintextPassword string) (string, error)

HashPassword generates a bcrypt hash of a plaintext password.

func (ss *ShortlinkService) SaveShortlink(shortlink *entities.Shortlink) (*entities.Shortlink, error)

SaveShortlink writes a shortlink to the DB.

func (*ShortlinkService) ValidateKind

func (ss *ShortlinkService) ValidateKind(kind string) error

ValidateKind checks if a kind is supported.

func (*ShortlinkService) ValidatePasswordLength

func (ss *ShortlinkService) ValidatePasswordLength(password string) error

ValidatePasswordLength checks if a password's length is valid.

func (*ShortlinkService) ValidateUserSlug

func (ss *ShortlinkService) ValidateUserSlug(slug string) error

ValidateUserSlug checks if a user-provided slug meets all requirements.

func (*ShortlinkService) VerifyPassword

func (ss *ShortlinkService) VerifyPassword(hashedPassword, plaintextPassword string) bool

VerifyPassword compares a bcrypt hash with a plaintext password.

type VisitService

type VisitService struct {
	DB     *sqlx.DB
	Logger *log.Logger
}

VisitService manages visits.

func (*VisitService) SaveVisit

func (vs *VisitService) SaveVisit(slug string, kind string, referer string, userAgent string) error

SaveVisit writes a visit to the DB.

Jump to

Keyboard shortcuts

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