utils

package
v0.0.0-...-9101988 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package utils contains various utilities

Index

Constants

This section is empty.

Variables

View Source
var (
	// DBDumpWrapper is a map of database dump to gzip functions based on DB.Type
	DBDumpWrapper = map[string]func(string) error{
		"MySQL": MySQLDumpToGz,
	}

	// DBCreateWrapper is a map is database creation functions based on DB.Type
	DBCreateWrapper = map[string]func(bool) error{
		"MySQL": MySQLCreateDB,
	}

	// DBLoadWrapper is a map of database load-from-gzip functions based on DB.Type
	DBLoadWrapper = map[string]func(string) error{
		"MySQL": MySQLLoadFromGz,
	}
)

The DB wrappers serve to map the various database functions to their respective types. This provides flexibility in the calling function without having to duplicate code and wrap in a whole bunch of if/else statements.

Functions

func AssetsFromTarGz

func AssetsFromTarGz(tmpDir, assetsBase string) error

AssetsFromTarGz extracts assets from a tar.gz. If an existing assets directory is found then the existing one is renamed assets.old, and then deleted after the process completes.

func AssetsToTarGz

func AssetsToTarGz(assetsDir, gzipFile string) error

AssetsToTarGz creates a tar.gz from the assets folder

func ByteToHr

func ByteToHr(b int64) string

ByteToHr returns a human readable size as a string

func CalcSize

func CalcSize(path string) (int64, error)

CalcSize returns the size of a directory or file

func CreateSSPak

func CreateSSPak(sspakFile string, files []string) error

CreateSSPak creates a regular POSIX tar file from a database and an assets archive

func ExtractSSPak

func ExtractSSPak(sspakFile, outDir string) error

ExtractSSPak extracts a SSPak (tar) file

func GzipFile

func GzipFile(file, output string) error

GzipFile will compress an existing file with gzip and save it was output

func HasEnoughSpace

func HasEnoughSpace(location string, requiredSize int64) error

HasEnoughSpace will return an error message if the provided location does not have sufficient storage space

func IsDir

func IsDir(path string) bool

IsDir returns if a path is a directory

func IsFile

func IsFile(path string) bool

IsFile returns if a path is a file

func MkDirIfNotExists

func MkDirIfNotExists(path string) error

MkDirIfNotExists will create a directory if it doesn't exist

func MySQLCreateDB

func MySQLCreateDB(dropDatabase bool) error

MySQLCreateDB a database, optionally dropping it

func MySQLDumpToGz

func MySQLDumpToGz(gzipFile string) error

MySQLDumpToGz uses mysqldump to stream a database dump directly into a gzip file

func MySQLLoadFromGz

func MySQLLoadFromGz(gzipSQLFile string) error

MySQLLoadFromGz loads a GZ database file into the database, streaming the gz file to the mysql cli.

func TarGZCompress

func TarGZCompress(inputFilePath, outputFilePath string) (err error)

TarGZCompress creates a archive from the folder inputFilePath. Only adds the last directory in inputFilePath to the archive, not the whole path. It tries to create the directory structure outputFilePath contains if it doesn't exist. It returns potential errors to be checked or nil if everything works.

func TarGZExtract

func TarGZExtract(inputFilePath, outputFilePath string) (err error)

TarGZExtract extracts a archive from the file inputFilePath. It tries to create the directory structure outputFilePath contains if it doesn't exist. It returns potential errors to be checked or nil if everything works.

Types

This section is empty.

Jump to

Keyboard shortcuts

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