util

package
v0.0.1 Latest Latest
Warning

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

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

Documentation

Overview

Package utils contains utility functions that are used everywhere in the app.

Index

Constants

View Source
const DEFAULT_GAME_REPO = "piepacker"
View Source
const DEFAULT_GAME_TAG = "latest"

GAME_TAG

Variables

This section is empty.

Functions

func AllFilesIn

func AllFilesIn(dir string) ([]string, error)

AllFilesIn recursively builds a list of the files in a given directory

func CaptureOutput

func CaptureOutput(f func()) string

CaptureOutput executes a function and capture all the text outputted to logs. Used in unit tests.

func ChannelStats

func ChannelStats(id string) chan int

func CoreExt

func CoreExt() string

CoreExt returns the libretro core extension for the current OS

func DatedName

func DatedName(path string) string

DatedName returns the name of a file with a date appended, without extension. It is used for savestates and screenshot names.

func DecodeYaml

func DecodeYaml(filename string) (k8s_runtime.Object, error)

DecodeYaml will read a yaml file found at path *filename* and transform it into a kubernetes runtime object. The caller can then make a type assertion on the runtime object.

func DocumentListByChunks

func DocumentListByChunks(ctx context.Context, col *firestore.CollectionRef, chunk int) ([]*firestore.DocumentSnapshot, error)

func EqualASCIIFold

func EqualASCIIFold(s, t string) bool

EqualASCIIFold returns true if s is equal to t with ASCII case folding.

func ExtractIP

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

func FileName

func FileName(path string) string

FileName returns the name of a file, without the path and extension.

func FromK8sCoreName

func FromK8sCoreName(coreName string) (piepacker.Key, error)

func FromUnixMillis

func FromUnixMillis(unixMillis int64) time.Time

func GameImageName

func GameImageName(gameName string) string

TODO: introduce game tags, which offer a way for us to version each game separately TODO: Geographical repos should also be introduced

func GetHostPublicIP

func GetHostPublicIP() string

GetHostPublicIP to get the public ip address. Only work if not behind NAT

func GetRemoteAddress

func GetRemoteAddress(conn *websocket.Conn) string

GetRemoteAddress returns public address of websocket connection

func HttpGet

func HttpGet(url string) ([]byte, int, error)

func InQueryParam

func InQueryParam(param string, r *http.Request) string

func IndexOfString

func IndexOfString(element string, data []string) int

IndexOfString returns the index of a string in a string slice or -1 if not found.

func IsLocalhost

func IsLocalhost(hostname string) bool

func IsPublicIP

func IsPublicIP(address string) bool

IsPublicIP checks if address is public address

func K8sCoreName

func K8sCoreName(k piepacker.Key) string

func LastPathParam

func LastPathParam(r *http.Request) string

func LinesInFile

func LinesInFile(r io.Reader) (int, error)

LinesInFile counts the number of lines in a file

func MinInt

func MinInt(x int, y int) int

func ReadStackTrace

func ReadStackTrace(data []byte)

func RetryExponential

func RetryExponential(backoff wait.Backoff, fn func() (bool, error)) error

func RetryLinear

func RetryLinear(period, timeout time.Duration, fn func() (bool, error)) error

func ShortHash

func ShortHash(val string) string

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice check wether a string is contain in a string slice.

func StringSliceContains

func StringSliceContains(slice []string, vals ...string) bool

StringSliceContains returns true iff the string slice contains ALL the values in vals

func WaitUntilTimeout

func WaitUntilTimeout(timeout, period time.Duration, f WaiterFunc) error

WaitUntilTimeout will execute f every period until timeout is reached

func WriteError

func WriteError(w http.ResponseWriter, httpStatus int, err error)

func WriteInternalError

func WriteInternalError(w http.ResponseWriter, msg string)

Types

type WaiterFunc

type WaiterFunc func() (bool, error)

WaiterFunc are functions for operations which are expected to eventually succeed. The return types are: - bool: whether the operation was successful - err: an unrecoverable error. If recoverable, set this to nil and set the bool to false.

Jump to

Keyboard shortcuts

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