Documentation
¶
Index ¶
- Constants
- Variables
- func Base62Decode(s string) (string, error)
- func Base62Encode(b []byte) string
- func GenReplyAliasEmail(sourceEmail, destEmail Email, domain string) (Email, Hash, error)
- func HashApiToken(salt, token string) string
- func NewPasswordHash(password string) (string, error)
- func RandString(nByte int) (string, error)
- func UserTypeAtoi(uStr string) int
- func UserTypeItoa(uInt int) string
- func ValidPassword(password, hashedPasword string) bool
- type Address
- type AddressBulkUpdateFields
- type AddressFilter
- type AddressMetadata
- type AddressType
- type ApiToken
- type ApiTokenBulkUpdateFields
- type ApiTokenFilter
- type Chain
- type ChainFilter
- type CustomDomain
- type CustomDomainFilter
- type DNSRecordType
- type DomainVerificationData
- type Email
- type Filter
- type Hash
- type Id
- type PaginationMetadata
- type User
- type UserFilter
- type UserType
Constants ¶
const ( DefaultPageSize int = 5 DefaulPageNumber int = 1 )
const ApiTokenPrefix = "ovtk"
Variables ¶
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
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
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 ¶
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
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 RandString ¶ added in v0.0.9
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 UserTypeItoa ¶ added in v0.3.1
func ValidPassword ¶ added in v0.0.3
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 ¶
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 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 ¶
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.
type ApiTokenBulkUpdateFields ¶ added in v0.15.0
type ApiTokenFilter ¶ added in v0.5.0
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.
type ChainFilter ¶ added in v0.6.0
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 ¶
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
type Filter ¶ added in v0.5.0
func NewFilter ¶ added in v0.5.0
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 ¶
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
type Id ¶
type Id string
Id represents a unique identifier based on ULID (Universally Unique Lexicographically Sortable Identifier)
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.
type UserFilter ¶ added in v0.5.0
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.