utils

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculatePage

func CalculatePage(ordinal, perPage int) int

CalculatePage calculates the page number for a message given its ordinal and messages per page. Formula: page = (ordinal - 1) / perPage + 1

func Decode

func Decode(r io.ReadCloser, body any) error

func DecodeValidate

func DecodeValidate(r io.ReadCloser, body any) error

func GenerateConfirmationCode

func GenerateConfirmationCode(length int) string

func GenerateRandomEmail

func GenerateRandomEmail() string

GenerateRandomEmail creates a random @invited.ru email address Format: {random_12_chars}@invited.ru This is used for invite-based registration to prevent email spoofing and ensure users don't get access to private boards

func GenerateRandomString

func GenerateRandomString(length int, charset string) string

GenerateRandomString generates a cryptographically secure random string using the provided charset and length

func GetIP

func GetIP(r *http.Request) (string, error)

func GetPage added in v0.1.1

func GetPage(r *http.Request) int

GetPage extracts the "page" query parameter from the request, defaulting to 1.

func HashSHA256

func HashSHA256(input string) string

func IntPtr

func IntPtr(i int) *int

intPtr returns a pointer to the given int value

func WriteErrorAndStatusCode

func WriteErrorAndStatusCode(w http.ResponseWriter, err error)

Types

type AllowedSources added in v0.1.3

type AllowedSources map[string]struct{}

AllowedSources holds a set of permitted referral source identifiers for O(1) membership tests. An empty AllowedSources means no filtering — all sources are accepted.

func NewAllowedSources added in v0.1.3

func NewAllowedSources(sources []string) AllowedSources

NewAllowedSources builds an AllowedSources from a slice of permitted identifiers.

func (AllowedSources) IsAllowed added in v0.1.3

func (a AllowedSources) IsAllowed(ref string) bool

IsAllowed reports whether ref is a permitted source.

Jump to

Keyboard shortcuts

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