entities

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// USER_STATUS_ACTIVE UserStatusActive is the status for an active user
	USER_STATUS_ACTIVE      = "ACTIVE"
	USER_STATUS_DEACTIVATED = "DEACTIVATED"
)

Variables

View Source
var (
	IP        = `` /* 659-byte string literal not displayed */
	Schema    = `((ftp|https?):\/\/)`
	Username  = `(\S+(:\S*)?@)`
	Path      = `((\/|\?|#)[^\s]*)`
	Port      = `(:(\d{1,5}))`
	UrlIP     = `([1-9]\d?|1\d\d|2[01]\d|22[0-3]|24\d|25[0-5])(\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])){2}(?:\.([0-9]\d?|1\d\d|2[0-4]\d|25[0-5]))`
	Subdomain = `((www\.)|([a-zA-Z0-9]+([-_\.]?[a-zA-Z0-9])*[a-zA-Z0-9]\.[a-zA-Z0-9]+))`

	MinLength   = 15
	MaxLength   = 2048
	Regex       = `^` + Schema + `?` + Username + `?` + `((` + IP + `|(\[` + IP + `\])|(([a-zA-Z0-9]([a-zA-Z0-9-_]+)?[a-zA-Z0-9]([-\.][a-zA-Z0-9]+)*)|(` + Subdomain + `?))?(([a-zA-Z\x{00a1}-\x{ffff}0-9]+-?-?)*[a-zA-Z\x{00a1}-\x{ffff}0-9]+)(?:\.([a-zA-Z\x{00a1}-\x{ffff}]{1,}))?))\.?` + Port + `?` + Path + `?$`
	FilterRegex = `(xxx|localhost|127\.0\.0\.1|\.lvh\.me|\.local|urlss?h\.)`
)

@see https://github.com/asaskevich/govalidator/blob/master/patterns.go

View Source
var (
	KeywordRegex = `^[a-zA-Z0-9-_]+$`
)

Functions

This section is empty.

Types

type BaseEntity

type BaseEntity struct {
	// CreatedAt is the date when the entity was created
	CreatedAt time.Time

	// UpdatedAt is the date when the entity was updated
	UpdatedAt time.Time
}

BaseEntity is a base model for all models

func NewBaseEntity

func NewBaseEntity() BaseEntity

NewBaseEntity creates a new base entity

type Email

type Email struct {
	Value string
}

Email is a domain entity for email

func NewEmail

func NewEmail(value string) (Email, error)

NewEmail creates a new email

type Keyword

type Keyword struct {
	identifier.ID
	Value string
}

Keyword is model for keywords attached to a url

func NewKeyword

func NewKeyword(keyword string) (Keyword, error)

NewKeyword creates a new keyword

type Password

type Password struct {
	Value string
}

Password contains user password information

func NewPassword

func NewPassword(value string) (Password, error)

NewPassword creates a new password

func (Password) Compare

func (p Password) Compare(hash, password string) (bool, error)

Compare compares the password hash against the passed in password string

type Token

type Token struct {
	APIKey               identifier.ID
	ResetPasswordExpires *time.Time
	ResetPasswordToken   *identifier.ID
	VerificationExpires  time.Time
	VerificationToken    identifier.ID
}

Token contains token information for a user

func NewToken

func NewToken() Token

type URL

type URL struct {
	// ID is the unique identifier for the url
	identifier.ID

	// UserID is the user id of the url owner
	UserId identifier.ID

	// ShortCode is the short code for the url
	ShortCode string

	// CustomAlias is the custom alias for the url
	CustomAlias string

	// OriginalURL is the original url
	OriginalUrl string

	// Hits is the number of hits for the url
	Hits uint

	// ExpiresOn is the expiration date for the url
	ExpiresOn time.Time

	// Keywords is a list of keywords for the url
	Keywords []Keyword

	// BaseEntity is the base entity for the url
	BaseEntity
}

URL represents an entity for a url

func NewUrl

func NewUrl(userId identifier.ID, originalUrl string, customAlias string, expiresOn time.Time, keywords []string) (*URL, error)

NewUrl creates a new URL entity

func (URL) GetCustomAlias added in v1.3.0

func (url URL) GetCustomAlias() string

func (URL) GetExpiresOn added in v1.3.0

func (url URL) GetExpiresOn() time.Time

func (URL) GetExpiryDuration added in v1.3.0

func (url URL) GetExpiryDuration() time.Duration

GetExpiryDuration returns as a time.Duration how long before the url expires This returns an absolute value after subtracting time.Now()

func (URL) GetKeywords added in v1.3.0

func (url URL) GetKeywords() []Keyword

func (URL) IsActive

func (url URL) IsActive() bool

IsActive checks if the url is active or not expired.

func (URL) Prefix

func (url URL) Prefix() string

Prefix returns the url prefix for logging

func (URL) SetCustomAlias added in v1.3.0

func (url URL) SetCustomAlias(customAlias string) error

func (URL) SetExpiresOn added in v1.3.0

func (url URL) SetExpiresOn(expiresOn time.Time)

func (URL) SetKeywords added in v1.3.0

func (url URL) SetKeywords(keywords []string) error

func (URL) UpdateExpiresOn added in v1.3.0

func (url URL) UpdateExpiresOn(expiresOn time.Time) error

UpdateExpiresOn updates the expiresOn field on a URL

type User

type User struct {
	// ID is the unique identifier for a user
	identifier.ID

	// BaseEntity is the base entity for a user
	BaseEntity

	// Email is the email address for a user
	Email

	// Password is the password for a user
	Password

	// Token is the token for a user
	Token

	// Verified is the verification status for a user
	Verified bool

	// Status is the status for a user
	Status string
}

User is a domain entity for user

func NewUser

func NewUser(email, password string) (User, error)

Jump to

Keyboard shortcuts

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