utils

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

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

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

func CleanupDirectory

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 DoesFileExists

func DoesFileExists(name string) bool

DoesFileExists checks if the file exists.

func FindInSlice

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

FindInSlice will return the index if a string is located in a slice of strings.

func GenerateAccessToken

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

func GeneratePhrase() string

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

func GenerateRandomDisplayColor

func GenerateRandomDisplayColor() int

GenerateRandomDisplayColor will return a random _hue_ to be used when displaying a user. The UI should determine the right saturation and lightness in order to make it look right.

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 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 IsUserAgentABot

func IsUserAgentABot(userAgent string) bool

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

func IsUserAgentAPlayer

func IsUserAgentAPlayer(userAgent string) bool

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

func IsValidURL

func IsValidURL(urlToTest string) bool

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

func Move

func Move(source, destination string) error

Move moves the file to destination.

func ReadRestURLParameter

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

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

func RenderPageContentMarkdown

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

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

RestEndpoint wraps a handler to use the rest endpoint helper.

func Restore

func Restore(backupFile string, databaseFile string) error

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

func StartPerformanceMonitor

func StartPerformanceMonitor(key string)

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

func ValidatedFfmpegPath

func ValidatedFfmpegPath(ffmpegPath string) string

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

func VerifyFFMpegPath

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