helper

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgInternalServer = "Internal server error"
	ErrMsgUnauthorized   = "Unauthorized"
	ErrMsgNotFound       = "Resource not found"
	ErrMsgBadRequest     = "Invalid request"
	ErrMsgForbidden      = "Access forbidden"
)

Safe error messages for clients

View Source
const (
	// Grams to other units
	GramsPerOunce = 28.3495
	GramsPerPound = 453.592
)

Weight conversion constants

Variables

This section is empty.

Functions

func BuildConfirmationEmailHTML added in v1.3.1

func BuildConfirmationEmailHTML(username, confirmURL string) string

BuildConfirmationEmailHTML returns the branded HTML body for a confirmation email.

func BuildConfirmationEmailText added in v1.3.1

func BuildConfirmationEmailText(username, confirmURL string) string

BuildConfirmationEmailText returns the plain-text body for a confirmation email.

func BuildEmailHTML added in v1.3.1

func BuildEmailHTML(title, preheaderText, bodyContent string) string

BuildEmailHTML wraps body content in a branded HTML email layout. title and preheaderText are HTML-escaped; bodyContent is trusted pre-built HTML.

func BuildMIMEMessage added in v1.3.1

func BuildMIMEMessage(
	fromName, fromAddr, to, subject, textBody, htmlBody string,
) ([]byte, error)

BuildMIMEMessage constructs a multipart/alternative MIME email message with proper headers.

func BuildPasswordResetEmailHTML added in v1.3.1

func BuildPasswordResetEmailHTML(newPassword string) string

BuildPasswordResetEmailHTML returns the branded HTML body for a password reset email.

func BuildPasswordResetEmailText added in v1.3.1

func BuildPasswordResetEmailText(newPassword string) string

BuildPasswordResetEmailText returns the plain-text body for a password reset email.

func ComparePtrString added in v0.11.0

func ComparePtrString(a, b *string) bool

func ConvertFromGrams added in v0.9.0

func ConvertFromGrams(weight float64, toUnit string) float64

ConvertFromGrams converts a weight from grams to the specified unit

func ConvertToGrams added in v0.9.0

func ConvertToGrams(weight float64, fromUnit string) float64

ConvertToGrams converts a weight from any unit to grams

func ConvertWeightUnit

func ConvertWeightUnit(unit string) string

func FormatWeight added in v0.9.0

func FormatWeight(weightInGrams float64, displayUnit string) string

FormatWeight formats a weight in grams to a human-readable string

func GenerateRandomCode added in v0.3.0

func GenerateRandomCode(length int) (string, error)

func IsValidEmail added in v0.4.1

func IsValidEmail(email string) bool

func IsValidUsername added in v1.4.0

func IsValidUsername(username string) bool

IsValidUsername checks that a username does not contain '@' to avoid ambiguity with email login.

func LogAndSanitize added in v0.16.0

func LogAndSanitize(err error, context string) string

LogAndSanitize logs the actual error internally and returns a safe message for the client

func StringToUint

func StringToUint(s string) (uint, error)

Types

type EmailSender added in v0.3.0

type EmailSender interface {
	SendEmail(to, subject, textBody, htmlBody string) error
}

EmailSender defines the interface for sending emails. Needed for testing without real SMTP server.

type SMTPClient added in v0.3.0

type SMTPClient struct {
	Server config.MailServer
}

SMTPClient struct implements EmailSender interface.

func (*SMTPClient) SendEmail added in v0.3.0

func (s *SMTPClient) SendEmail(to, subject, textBody, htmlBody string) error

SendEmail sends an email using the SMTP protocol with proper MIME multipart/alternative formatting. MailIdentity must be a valid email address (validated at startup) — used as envelope sender and From address. MailUsername is the SMTP authentication login credential.

Jump to

Keyboard shortcuts

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