entities

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPageSize  int = 5
	DefaulPageNumber int = 1
)
View Source
const ApiTokenPrefix = "ovtk"

Variables

View Source
var (
	// ErrValidation is returned when there's a validation error
	ErrValidation = errors.New("validation error")
	// ErrDuplicateEntry is returned when a duplicate entry is detected
	ErrDuplicateEntry = errors.New("duplicate entry")
	// ErrNotFound is returned when a requested resource is not found
	ErrNotFound = errors.New("not found")
	// ErrConfiguration is returned when there's a configuration error
	ErrConfiguration = errors.New("configuration error")
	// ErrGeneral is returned for general backend errors
	ErrGeneral = errors.New("general backend error")
	// ErrNotAuthorized is returned when operation requested by the user is not authorized
	ErrNotAuthorized = errors.New("requested operation is not authorized for the user")
	// ErrDatabase is returned when database operation failed, except when "not found" is returned
	ErrDatabase = errors.New("database error")
)

Functions

func Base62Decode added in v0.0.9

func Base62Decode(s string) (string, error)

Base62Decode converts a base62 encoded string back to a string. Base62 decoding interprets the characters 0-9, a-z, and A-Z to convert the string back to its original binary data.

Parameters:

  • s: the base62 encoded string to decode

Returns:

  • string: the decoded string
  • error: an error if the input is not a valid base62 string

func Base62Encode added in v0.0.9

func Base62Encode(b []byte) string

Base62Encode converts a byte slice to a base62 encoded string. Base62 encoding uses the characters 0-9, a-z, and A-Z to represent binary data as a string.

Parameters:

  • b: the byte slice to encode

Returns:

  • string: the base62 encoded representation of the input

func GenReplyAliasEmail

func GenReplyAliasEmail(sourceEmail, destEmail Email, domain string) (Email, Hash, error)

GenReplyAliasEmail generates a reply alias email address based on the sender's email, the original alias email, and the domain. It returns the generated Email, a Hash, and an error if any occurred during the process.

func HashApiToken added in v0.0.9

func HashApiToken(salt, token string) string

HashApiToken creates a SHA-256 hash of a token by prepending the salt. The salt adds randomness to prevent rainbow table attacks. Returns the hex-encoded hash string.

func NewPasswordHash added in v0.0.3

func NewPasswordHash(password string) (string, error)

func RandString added in v0.0.9

func RandString(nByte int) (string, error)

RandString generates a cryptographically secure random string of specified byte length. It uses crypto/rand to generate random bytes which are then encoded using base64 URL-safe encoding.

Parameters:

  • nByte: the number of random bytes to generate.

Returns:

  • string: the base64 URL-safe encoded random string.
  • error: an error if random byte generation fails.

func UserTypeAtoi added in v0.3.1

func UserTypeAtoi(uStr string) int

func UserTypeItoa added in v0.3.1

func UserTypeItoa(uInt int) string

func ValidPassword added in v0.0.3

func ValidPassword(password, hashedPasword string) bool

Types

type Address

type Address struct {
	ID             Id
	Type           AddressType
	Email          Email
	ForwardAddress *Address
	Owner          User
	Metadata       AddressMetadata
	CreatedAt      time.Time
	UpdatedAt      time.Time
	UpdatedBy      User
	Active         bool
}

Address represents an email address with associated metadata and ownership information. It can be of different types (alias, reply alias, protected, or external) and may have a forward address for routing purposes.

func (*Address) Validate

func (a *Address) Validate() error

Validate checks if the Address object is valid according to the defined rules. It returns an error if any validation fails, or nil if the Address is valid. The validation includes checking the ID, email, forward address (if applicable), and owner ID. It also enforces rules specific to protected and external addresses.

type AddressBulkUpdateFields added in v0.15.0

type AddressBulkUpdateFields struct {
	MetadataComment     *string
	MetadataServiceName *string
	Active              *bool
	UpdatedById         *Id
}

type AddressFilter added in v0.5.0

type AddressFilter struct {
	Filter
	Types             []AddressType
	Emails            []Email
	Owners            []Id
	ServiceNames      []string
	ForwardAddressIds []Id
	Active            *bool
	Search            string
}

func NewAddressFilter added in v0.5.0

func NewAddressFilter(input map[string][]string) (AddressFilter, error)

NewAddressFilter parses and returns an AddressFilter from the given input map. Populates AddressFilter fields such as Types, Emails, Owners, and ServiceNames based on the corresponding filter keys provided in input. Returns an error if any validation fails (e.g., unsupported address type).

type AddressMetadata

type AddressMetadata struct {
	Comment     string
	ServiceName string
}

AddressMetadata contains additional information about an address. It includes a comment for user notes and the name of the associated service.

type AddressType

type AddressType int8
const (
	AliasAddress AddressType = iota
	ReplyAliasAddress
	ProtectedAddress
	ExternalAddress
)

type ApiToken

type ApiToken struct {
	ID          Id
	Name        string
	Token       string // for runtime purposes only, should not be stored
	TokenHash   string
	Salt        string
	Description string
	Owner       User
	Expiration  time.Time
	Active      bool
	CreatedAt   time.Time
	UpdatedAt   time.Time
	UpdatedBy   User
}

ApiToken represents an API token with its associated metadata.

func NewToken

func NewToken(expiration time.Time, name, description string, owner User) (*ApiToken, error)

NewToken creates a new ApiToken with the given expiration, description, and owner.

func (*ApiToken) Expired

func (t *ApiToken) Expired() bool

Expired checks if the ApiToken has expired.

func (*ApiToken) Validate

func (t *ApiToken) Validate() error

Validate checks if the ApiToken's fields are valid.

type ApiTokenBulkUpdateFields added in v0.15.0

type ApiTokenBulkUpdateFields struct {
	Description *string
	Active      *bool
	UpdatedById *Id
}

type ApiTokenFilter added in v0.5.0

type ApiTokenFilter struct {
	Filter
	UserIds []Id
	Active  *bool
}

func NewApiTokensFilter added in v0.5.0

func NewApiTokensFilter(input map[string][]string) (ApiTokenFilter, error)

NewApiTokensFilter constructs an ApiTokenFilter using the provided input map. Only the generic Filter fields are considered; no additional fields are set. Returns an error if any value in the input filter causes validation to fail.

type Chain

type Chain struct {
	Hash            Hash
	FromAddress     Address
	ToAddress       Address
	OrigFromAddress Address
	OrigToAddress   Address
	CreatedAt       time.Time
	UpdatedAt       time.Time
	UpdatedBy       User
}

Chain represents a link between two addresses with a hash and creation timestamp.

func (Chain) Validate

func (c Chain) Validate() error

Validate checks the integrity of the Chain structure. It validates the hash, from address, and to address. It also ensures the hash matches the one generated from the email addresses. Returns an error if any validation fails.

type ChainFilter added in v0.6.0

type ChainFilter struct {
	Filter
	OrigFromAddrIds []Id
	OrigToAddrIds   []Id
	FromAddrsIds    []Id
	ToAddrIds       []Id
}

type CustomDomain added in v0.20.0

type CustomDomain struct {
	ID               Id
	Name             string
	Global           bool
	Owner            User
	CreatedAt        time.Time
	UpdatedAt        time.Time
	UpdatedBy        User
	Active           bool
	Verified         bool
	VerifiedAt       time.Time
	VerificationData DomainVerificationData
}

func (*CustomDomain) Validate added in v0.20.0

func (cd *CustomDomain) Validate() error

type CustomDomainFilter added in v0.20.0

type CustomDomainFilter struct {
	Filter
	Active        *bool
	Verified      *bool
	Owners        []Id
	IncludeGlobal bool
	DomainNames   []string
}

func NewCustomDomainFilter added in v0.20.0

func NewCustomDomainFilter(input map[string][]string) (CustomDomainFilter, error)

type DNSRecordType added in v0.22.0

type DNSRecordType string
const (
	CNAMERecord DNSRecordType = "cname"
	TXTRecord   DNSRecordType = "txt"
)

type DomainVerificationData added in v0.22.0

type DomainVerificationData struct {
	RecordType             DNSRecordType
	Name                   string
	Value                  string
	LastVerificationResult string
}

type Email

type Email string

Email represents an email address as a string type

func GenAliasEmail

func GenAliasEmail(domain string, dict []string, prefix *string) (Email, error)

GenAliasEmail generates an alias email address using the provided domain and dictionary. Parameters:

  • domain: the domain part of the email address (e.g., "example.com")
  • dict: slice of strings used as a word dictionary to generate email aliases

Returns:

  • Email: the generated alias email address
  • error: error if validation fails or random number generation fails

func (Email) String

func (e Email) String() string

String returns the string representation of the Email

func (Email) Validate

func (e Email) Validate() error

Validate checks if the Email is a valid email address

type Filter added in v0.5.0

type Filter struct {
	Page     int
	PageSize int
	Ids      []Id
}

func NewFilter added in v0.5.0

func NewFilter(input map[string][]string) (Filter, error)

NewFilter parses and returns a Filter from the given input map. The input map is expected to contain string slices for filter keys like "id", "page", and "page_size". "id": a list of string ids (will be converted to Id type) "page": page number (only the first element is used if slice contains more items) "page_size": size of the page (only the first element is used)

Defaults are assigned for Page and PageSize if not present or set to zero. Returns an error if "page" or "page_size" values are invalid.

type Hash

type Hash string

Hash represents a SHA-512/256 hash as a string.

func NewHash

func NewHash(s1, s2 string) Hash

NewHash creates a new Hash from two input strings. It concatenates the inputs with a '+' separator and generates a SHA-512/256 hash.

func SimpleHash added in v0.24.0

func SimpleHash(s string) Hash

func (Hash) String

func (h Hash) String() string

String returns the string representation of the Hash.

func (Hash) Validate

func (h Hash) Validate() error

Validate checks if the Hash is valid. It returns an error if the hash length is not 64 characters or if it contains invalid characters.

type Id

type Id string

Id represents a unique identifier based on ULID (Universally Unique Lexicographically Sortable Identifier)

func NewId

func NewId() Id

NewId generates a new Id using ULID

func (Id) String

func (id Id) String() string

String returns the string representation of the Id

func (Id) Validate

func (id Id) Validate() error

Validate checks if the Id is valid

type PaginationMetadata added in v0.5.0

type PaginationMetadata struct {
	CurrentPage  int
	PageSize     int
	FirstPage    int
	LastPage     int
	TotalRecords int
}

func GetPaginationMetadata added in v0.5.0

func GetPaginationMetadata(page, pageSize int, count int64) PaginationMetadata

GetPaginationMetadata generates pagination metadata based on the provided page, pageSize, and total record count.

Parameters:

  • page: The current page number (starting from 1).
  • pageSize: The number of records per page.
  • count: The total number of records available.

Returns:

PaginationMetadata struct filled with pagination details. If count or pageSize
is zero, returns an empty PaginationMetadata struct.

type User

type User struct {
	ID             Id
	Type           UserType
	Login          string
	FirstName      string
	LastName       string
	PasswordHash   string
	FailedAttempts int
	LockoutUntil   time.Time
	CreatedAt      time.Time
	UpdatedAt      time.Time
	UpdatedBy      *User
	CreatedBy      *User
	Active         bool
}

User represents a user in the system with various attributes.

func (User) String

func (u User) String() string

String returns a string representation of the User, combining FirstName and LastName.

func (User) Validate

func (u User) Validate() error

Validate checks if the User object is valid and returns an error if not.

type UserFilter added in v0.5.0

type UserFilter struct {
	Filter
	Types  []UserType
	Logins []string
	Active *bool
}

func NewUserFilter added in v0.5.0

func NewUserFilter(input map[string][]string) (UserFilter, error)

NewUserFilter parses and returns a UserFilter from the given input map. Populates UserFilter fields like Types and Logins based on filter keys. Returns an error if the user type value is not supported or invalid.

type UserType

type UserType int8
const (
	RegularUser UserType = iota
	AdminUser
	MilterUser
)

Jump to

Keyboard shortcuts

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