utils

package module
v0.0.0-...-bbb8a54 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2023 License: MIT Imports: 21 Imported by: 0

README

stablecog/go-apps/utils

Various shared helpers and utilities used by the other modules in this workspace.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RuntimeCaller = runtime.Caller

Functions

func FormatPrompt

func FormatPrompt(s string) string

FormatPrompt applies formatting to a prompt string e.g. " hello world " -> "hello world"

func GetCountryCode

func GetCountryCode(r *http.Request) string

Retrieves a country code via request header, prefer cloudflare, then vercel

func GetDefaultServerUrl

func GetDefaultServerUrl() string

func GetEnv

func GetEnv(key string, fallback string) string

func GetImageSizeFromUrl

func GetImageSizeFromUrl(imageUrl string) (bytes int64, err error)

Retrieves the download size of an image via headers

func GetImageWidthHeightFromUrl

func GetImageWidthHeightFromUrl(imageUrl string, maxSizeBytes int64) (width, height int32, err error)

func IsSha256Hash

func IsSha256Hash(str string) bool

func IsValidHTTPURL

func IsValidHTTPURL(urlStr string) bool

Validates that a URL is valid with http or https scheme

func ParseIsoTime

func ParseIsoTime(isoTime string) (time.Time, error)

Parse an iso string into a time.Time e.g. 2023-01-27T14:40:53.858Z represents javascript toISOString()

func RelativeTimeStr

func RelativeTimeStr(t time.Time) string

Create a relative time string from now to past (e.g., "1h ago")

func RemoveLineBreaks

func RemoveLineBreaks(s string) string

RemoveLineBreaks removes all line breaks from a string e.g. "hello\nworld" -> "hello world"

func RemoveRedundantSpaces

func RemoveRedundantSpaces(s string) string

RemoveRedundantSpaces removes all redundant spaces from a string e.g. " hello world " -> " hello world "

func RootDir

func RootDir() string

Returns the root directory of the project

func Sha256

func Sha256(s string) string

func TimeToIsoString

func TimeToIsoString(ts time.Time) string

Types

type ClientDeviceInfo

type ClientDeviceInfo struct {
	DeviceType    ClientDeviceType
	DeviceOs      string
	DeviceBrowser string
}

func GetClientDeviceInfo

func GetClientDeviceInfo(r *http.Request) ClientDeviceInfo

type ClientDeviceType

type ClientDeviceType string

Parses user agent to return device type, os, and browser

const (
	Desktop ClientDeviceType = "desktop"
	Mobile  ClientDeviceType = "mobile"
	Tablet  ClientDeviceType = "tablet"
	Bot     ClientDeviceType = "bot"
	Unknown ClientDeviceType = "unknown"
)

type S3Data

type S3Data struct {
	BucketPublic                   string
	BucketPrivate                  string
	BucketPrivateOutputQueueFolder string
	Hostname                       string
	PrivateUrl                     string
	AccountId                      string
	AccessKeyId                    string
	SecretKey                      string
}

func GetS3Data

func GetS3Data() S3Data

Directories

Path Synopsis
Apply various colors to text via ansi escape codes
Apply various colors to text via ansi escape codes

Jump to

Keyboard shortcuts

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