Documentation
¶
Overview ¶
Package utils contains utility functions that are used everywhere in the app.
Index ¶
- Constants
- func AllFilesIn(dir string) ([]string, error)
- func CaptureOutput(f func()) string
- func ChannelStats(id string) chan int
- func CoreExt() string
- func DatedName(path string) string
- func DecodeYaml(filename string) (k8s_runtime.Object, error)
- func DocumentListByChunks(ctx context.Context, col *firestore.CollectionRef, chunk int) ([]*firestore.DocumentSnapshot, error)
- func EqualASCIIFold(s, t string) bool
- func ExtractIP(r *http.Request) (string, error)
- func FileName(path string) string
- func FromK8sCoreName(coreName string) (piepacker.Key, error)
- func FromUnixMillis(unixMillis int64) time.Time
- func GameImageName(gameName string) string
- func GetHostPublicIP() string
- func GetRemoteAddress(conn *websocket.Conn) string
- func HttpGet(url string) ([]byte, int, error)
- func InQueryParam(param string, r *http.Request) string
- func IndexOfString(element string, data []string) int
- func IsLocalhost(hostname string) bool
- func IsPublicIP(address string) bool
- func K8sCoreName(k piepacker.Key) string
- func LastPathParam(r *http.Request) string
- func LinesInFile(r io.Reader) (int, error)
- func MinInt(x int, y int) int
- func ReadStackTrace(data []byte)
- func RetryExponential(backoff wait.Backoff, fn func() (bool, error)) error
- func RetryLinear(period, timeout time.Duration, fn func() (bool, error)) error
- func ShortHash(val string) string
- func StringInSlice(a string, list []string) bool
- func StringSliceContains(slice []string, vals ...string) bool
- func WaitUntilTimeout(timeout, period time.Duration, f WaiterFunc) error
- func WriteError(w http.ResponseWriter, httpStatus int, err error)
- func WriteInternalError(w http.ResponseWriter, msg string)
- type WaiterFunc
Constants ¶
const DEFAULT_GAME_REPO = "piepacker"
const DEFAULT_GAME_TAG = "latest"
GAME_TAG
Variables ¶
This section is empty.
Functions ¶
func AllFilesIn ¶
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 DatedName ¶
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 ¶
EqualASCIIFold returns true if s is equal to t with ASCII case folding.
func FromUnixMillis ¶
func GameImageName ¶
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 ¶
GetRemoteAddress returns public address of websocket connection
func IndexOfString ¶
IndexOfString returns the index of a string in a string slice or -1 if not found.
func IsLocalhost ¶
func IsPublicIP ¶
IsPublicIP checks if address is public address
func K8sCoreName ¶
func LastPathParam ¶
func LinesInFile ¶
LinesInFile counts the number of lines in a file
func ReadStackTrace ¶
func ReadStackTrace(data []byte)
func StringInSlice ¶
StringInSlice check wether a string is contain in a string slice.
func StringSliceContains ¶
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 ¶
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.