helpers

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(hash, password string) bool

CheckPassword compares a hashed password with a plain-text candidate.

func Clamp

func Clamp(value, min, max int) int

Clamp restricts a value between min and max.

func Contains

func Contains(haystack, needle string) bool

Contains checks if needle exists in haystack (case-insensitive).

func Env

func Env(key, fallback string) string

Env reads an env variable with a fallback default.

func Excerpt

func Excerpt(s string, words int) string

Excerpt returns the first n words from a string.

func FormatBytes

func FormatBytes(bytes int64) string

FormatBytes converts bytes to human-readable: 1536 → "1.50 KB".

func FormatDate

func FormatDate(t time.Time) string

FormatDate formats time as "Jan 2, 2006 3:04 PM".

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes a plain-text password using bcrypt.

func MapKeys

func MapKeys(m map[string]interface{}) []string

MapKeys returns the keys of a map.

func Mask

func Mask(s string, showFirst, showLast int) string

Mask masks a string showing only first/last n chars: "secret123" → "se*****23".

func RandomString

func RandomString(n int) string

RandomString generates a cryptographically random hex string of n bytes.

func Slugify

func Slugify(s string) string

Slugify converts a string to a URL-friendly slug.

func StripHTML

func StripHTML(s string) string

StripHTML removes all HTML tags from a string.

func StructToMap

func StructToMap(v interface{}) (map[string]interface{}, error)

StructToMap converts a struct to map[string]interface{} via JSON.

func TimeAgo

func TimeAgo(t time.Time) string

TimeAgo returns a human-readable relative time: "5 minutes ago".

func Title

func Title(s string) string

Title converts a string to title case: "hello world" → "Hello World".

func Truncate

func Truncate(s string, max int) string

Truncate shortens a string to max length, appending "..." if truncated.

Types

type PaginateResult

type PaginateResult struct {
	Page       int   `json:"page"`
	PerPage    int   `json:"per_page"`
	Total      int64 `json:"total"`
	TotalPages int   `json:"total_pages"`
}

PaginateResult holds pagination metadata returned by Paginate.

func Paginate

func Paginate(db *gorm.DB, page, perPage int, dest interface{}) (*PaginateResult, error)

Paginate executes a counted, offset/limit query on db and populates dest. page is clamped to a minimum of 1. perPage is clamped to 15 if outside [1,100].

Jump to

Keyboard shortcuts

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