utils

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Avg added in v0.0.12

func Avg(values []float64) float64

Avg will return the average value from a slice of float64s.

func Backup added in v0.0.6

func Backup(db *sql.DB, backupFile string)

Backup will backup the provided instance of the database to the specified file.

func CleanupDirectory added in v0.0.8

func CleanupDirectory(path string)

CleanupDirectory removes the directory and makes it fresh again. Throws fatal error on failure.

func Copy

func Copy(source, destination string) error

Copy copies the file to destination.

func DecodeBase64Image added in v0.1.0

func DecodeBase64Image(url string) (bytes []byte, extension string, err error)

DecodeBase64Image decodes a base64 image string into a byte array, returning the extension (including dot) for the content type.

func DoesFileExists

func DoesFileExists(name string) bool

DoesFileExists checks if the file exists.

func FindInSlice added in v0.0.8

func FindInSlice(slice []string, val string) (int, bool)

FindInSlice will return if a string is in a slice, and the index of that string.

func Float64MapToSlice added in v0.0.12

func Float64MapToSlice(float64Map map[string]float64) []float64

Float64MapToSlice is a convenience function to convert a map of floats into.

func GenerateAccessToken added in v0.0.6

func GenerateAccessToken() (string, error)

GenerateAccessToken will generate and return an access token.

func GenerateClientIDFromRequest

func GenerateClientIDFromRequest(req *http.Request) string

GenerateClientIDFromRequest generates a client id from the provided request.

func GeneratePhrase added in v0.0.8

func GeneratePhrase() string

GeneratePhrase will generate and return a random string consisting of our word list.

func GenerateRandomDisplayColor added in v0.0.8

func GenerateRandomDisplayColor(maxColor int) int

GenerateRandomDisplayColor will return a random number that is used for referencing a color value client-side. These colors are seen as --theme-user-colors-n.

func GenerateRandomString added in v0.1.0

func GenerateRandomString(n int) (string, error)

GenerateRandomString returns a URL-safe, base64 encoded securely generated random string. It will return an error if the system's secure random number generator fails to function correctly, in which case the caller should not continue.

func GetAveragePerformance

func GetAveragePerformance(key string) float64

GetAveragePerformance will return the average durations for the event.

func GetCacheDurationSecondsForPath

func GetCacheDurationSecondsForPath(filePath string) int

GetCacheDurationSecondsForPath will return the number of seconds to cache an item.

func GetHashtagsFromText added in v0.0.11

func GetHashtagsFromText(text string) []string

GetHashtagsFromText returns all the #Hashtags from a string.

func GetHostnameFromURL added in v0.0.11

func GetHostnameFromURL(u url.URL) string

GetHostnameFromURL will return the hostname component from a URL string.

func GetHostnameFromURLString added in v0.0.11

func GetHostnameFromURLString(s string) string

GetHostnameFromURLString will return the hostname component from a URL object.

func GetHostnameWithoutPortFromURLString added in v0.1.2

func GetHostnameWithoutPortFromURLString(s string) string

GetHostnameWithoutPortFromURLString will return the hostname component without the port from a URL object.

func GetIPAddressFromRequest

func GetIPAddressFromRequest(req *http.Request) string

GetIPAddressFromRequest returns the IP address from a http request.

func GetIndexFromFilePath

func GetIndexFromFilePath(path string) string

GetIndexFromFilePath is a utility that will return the index/key/variant name in a full path.

func GetRelativePathFromAbsolutePath

func GetRelativePathFromAbsolutePath(path string) string

GetRelativePathFromAbsolutePath gets the relative path from the provided absolute path.

func IntPercentage added in v0.0.12

func IntPercentage(x, total int) int

IntPercentage returns an int percentage of a number.

func IsHostnameInternal added in v0.1.2

func IsHostnameInternal(hostname string) bool

IsHostnameInternal will attempt to determine if the hostname is internal to this server's network or is the loopback address.

func IsUserAgentABot

func IsUserAgentABot(userAgent string) bool

IsUserAgentABot returns if a web client user-agent is seen as a bot.

func IsUserAgentAPlayer added in v0.0.9

func IsUserAgentAPlayer(userAgent string) bool

IsUserAgentAPlayer returns if a web client user-agent is seen as a media player.

func IsValidURL added in v0.0.9

func IsValidURL(urlToTest string) bool

IsValidURL will return if a URL string is a valid URL or not.

func MakeSafeStringOfLength added in v0.1.0

func MakeSafeStringOfLength(s string, length int) string

MakeSafeStringOfLength will take a string and strip HTML tags, trim whitespace, and limit the length.

func Median added in v0.0.12

func Median(input []float64) float64

Median gets the median number in a slice of numbers.

func MigrateCustomEmojiLocations added in v0.1.0

func MigrateCustomEmojiLocations()

MigrateCustomEmojiLocations migrates custom emoji from the old location to the new location.

func MinMax added in v0.0.12

func MinMax(array []float64) (float64, float64)

MinMax will return the min and max values from a slice of float64s.

func Move

func Move(source, destination string) error

Move moves the file at source to destination.

func RandomIndex added in v0.0.11

func RandomIndex(max int) int

RandomIndex returns a random integer that is at most the `max` parameter.

func ReadRestURLParameter added in v0.0.9

func ReadRestURLParameter(r *http.Request, parameterName string) (string, error)

ReadRestURLParameter will return the parameter from the request of the requested name.

func RenderPageContentMarkdown added in v0.0.6

func RenderPageContentMarkdown(raw string) string

RenderPageContentMarkdown will return HTML specifically handled for the user-specified page content.

func RenderSimpleMarkdown

func RenderSimpleMarkdown(raw string) string

RenderSimpleMarkdown will return HTML without sanitization or specific formatting rules.

func RestEndpoint added in v0.0.9

func RestEndpoint(pattern string, handler http.HandlerFunc) (string, http.HandlerFunc)

RestEndpoint wraps a handler to use the rest endpoint helper.

func Restore added in v0.0.6

func Restore(backupFile string, databaseFile string) error

Restore will attempt to restore the database using a specified backup file.

func ShuffleStringSlice added in v0.0.12

func ShuffleStringSlice(s []string) []string

ShuffleStringSlice will shuffle a slice of strings.

func StartPerformanceMonitor

func StartPerformanceMonitor(key string)

StartPerformanceMonitor will keep track of the start time of this event.

func StringMapKeys added in v0.0.11

func StringMapKeys(stringMap map[string]interface{}) []string

StringMapKeys returns a slice of string keys from a map.

func StringSliceToMap added in v0.0.11

func StringSliceToMap(stringSlice []string) map[string]interface{}

StringSliceToMap is a convenience function to convert a slice of strings into a map using the string as the key.

func StripHTML added in v0.1.0

func StripHTML(s string) string

StripHTML will strip HTML tags from a string.

func Sum added in v0.0.12

func Sum(values []float64) float64

Sum returns the sum of a slice of values.

func ValidatedFfmpegPath added in v0.0.6

func ValidatedFfmpegPath(ffmpegPath string) string

ValidatedFfmpegPath will take a proposed path to ffmpeg and return a validated path.

func VerifyFFMpegPath added in v0.0.6

func VerifyFFMpegPath(path string) error

VerifyFFMpegPath verifies that the path exists, is a file, and is executable.

Types

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool // Valid is true if Time is not NULL
}

NullTime is a custom nullable time for representing datetime.

func (NullTime) MarshalJSON

func (nt NullTime) MarshalJSON() ([]byte, error)

MarshalJSON implements the JSON marshal function.

func (*NullTime) Scan

func (nt *NullTime) Scan(value interface{}) error

Scan implements the Scanner interface.

func (NullTime) UnmarshalJSON

func (nt NullTime) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the JSON unmarshal function.

func (NullTime) Value

func (nt NullTime) Value() (driver.Value, error)

Value implements the driver Value interface.

Jump to

Keyboard shortcuts

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