utils

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllowedExtensions = map[string]string{
	".css":   "text/css",
	".js":    "application/javascript",
	".png":   "image/png",
	".jpg":   "image/jpeg",
	".jpeg":  "image/jpeg",
	".ico":   "image/x-icon",
	".svg":   "image/svg+xml",
	".webp":  "image/webp",
	".gif":   "image/gif",
	".json":  "application/json",
	".map":   "application/octet-stream",
	".wasm":  "application/wasm",
	".woff":  "font/woff",
	".woff2": "font/woff2",
	".ttf":   "font/ttf",
	".otf":   "font/otf",
	".wav":   "audio/wav",
	".mp3":   "audio/mpeg",
	".ogg":   "audio/ogg",
	".html":  "text/html",
	".txt":   "text/plain; charset=utf-8",
	".xml":   "application/xml",
}

Functions

func ContainsLogLevel

func ContainsLogLevel(line, level string) bool

func FileOrDirectoryExists

func FileOrDirectoryExists(path string) bool

func GenerateRandomString added in v1.3.0

func GenerateRandomString(n int) string

func GetAllowedMime

func GetAllowedMime(path string) (string, bool)

func GetBasePath

func GetBasePath() (string, error)

func GetCodeMessage

func GetCodeMessage(code int) string

func GetIPAddresses

func GetIPAddresses() (string, string, error)

func GetMimeTypeFromCompressedFilePath

func GetMimeTypeFromCompressedFilePath(path string) string

func GetTLSVersion

func GetTLSVersion(req *http.Request) string

func IsAllowedExtension

func IsAllowedExtension(path string) bool

func IsFileCompressed added in v1.5.0

func IsFileCompressed(filePath string) bool

IsFileCompressed reports whether a file path ends with a known compression extension. This is used to decide whether a pre-compressed asset is being served.

func ParseLogTimestamp

func ParseLogTimestamp(line string) (time.Time, error)

func SHA256Base64URL added in v1.6.0

func SHA256Base64URL(verifier string) string

SHA256Base64URL generates a PKCE code_challenge from a verifier RFC 7636 compliant: BASE64URL-ENCODE(SHA256(verifier))

func SanitizeInput

func SanitizeInput(input string) string

func StringToSameSite added in v1.5.0

func StringToSameSite(s string) http.SameSite

func URLEncode added in v1.6.0

func URLEncode(s string) string

Types

type APIResponse added in v1.4.0

type APIResponse struct {
	Success bool        `json:"success"`
	Message string      `json:"message,omitempty"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
}

APIResponse is the standard structure for all API responses

type HTTPError

type HTTPError struct {
	Code    int
	Message string
}

func NewHTTPError

func NewHTTPError(code int, message string) *HTTPError

func (*HTTPError) Error

func (e *HTTPError) Error() string

Jump to

Keyboard shortcuts

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